@@ -69,8 +69,8 @@ private void AssignVariables(FromImportStatement node, IImportSearchResult impor
69
69
DeclareVariable ( variableModule , memberName , imports , variableName , node . StartIndex , nameExpression ) ;
70
70
}
71
71
72
- if ( imports is IImportChildrenSource cs
73
- && cs . TryGetChildImport ( memberName , out var csr )
72
+ if ( imports is IImportChildrenSource cs
73
+ && cs . TryGetChildImport ( memberName , out var csr )
74
74
&& HandleImportSearchResult ( csr , variableModule , null , names [ i ] , out var childModule ) ) {
75
75
76
76
_importedVariableHandler . EnsureModule ( childModule ) ;
@@ -119,17 +119,31 @@ private void DeclareVariable(PythonVariableModule variableModule, string memberN
119
119
// Value may be variable or submodule. If it is variable, we need it in order to add reference.
120
120
var variable = _importedVariableHandler . GetVariable ( variableModule , memberName ) ;
121
121
122
- // If nothing is exported, variables are still accessible.
123
- value = value ?? member as PythonVariableModule ?? ( variable ? . Value != null ? variable : member ) ?? Eval . UnknownType ;
122
+ if ( member is PythonVariableModule vm && vm . Equals ( variable ? . Value ) ) {
123
+ // If member is submodule, use actual variable so it can be linked through for goto definition.
124
+ value = variable ;
125
+ } else if ( value == null ) {
126
+ if ( member is PythonVariableModule ) {
127
+ // If member is submodule, use it.
128
+ value = member ;
129
+ } else if ( variable ? . Value != null ) {
130
+ // Otherwise use variable, if available so references can be linked.
131
+ value = variable ;
132
+ } else if ( member != null ) {
133
+ value = member ;
134
+ } else {
135
+ value = Eval . UnknownType ;
136
+ }
137
+ }
124
138
}
125
139
126
140
// Do not allow imported variables to override local declarations
127
141
var canOverwrite = CanOverwriteVariable ( variableName , importPosition , value ) ;
128
-
142
+
129
143
// Do not declare references to '*'
130
144
var locationExpression = nameLocation is NameExpression nex && nex . Name == "*" ? null : nameLocation ;
131
145
Eval . DeclareVariable ( variableName , value , VariableSource . Import , locationExpression , canOverwrite ) ;
132
-
146
+
133
147
// Make sure module is loaded and analyzed.
134
148
if ( value is IPythonModule m ) {
135
149
ModuleResolution . GetOrLoadModule ( m . Name ) ;
@@ -141,8 +155,8 @@ private bool CanOverwriteVariable(string name, int importPosition, IMember newVa
141
155
if ( v == null ) {
142
156
return true ; // Variable does not exist
143
157
}
144
-
145
- if ( newValue . IsUnknown ( ) ) {
158
+
159
+ if ( newValue . IsUnknown ( ) ) {
146
160
return false ; // Do not overwrite potentially good value with unknowns.
147
161
}
148
162
0 commit comments