-
Notifications
You must be signed in to change notification settings - Fork 93
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SONARPY-2310: Partly support wildcard import #2167
Conversation
6ae107f
to
017a351
Compare
@@ -61,10 +62,15 @@ public TypeInferenceV2(TypeTable projectLevelTypeTable, PythonFile pythonFile, S | |||
} | |||
|
|||
public Map<SymbolV2, Set<PythonType>> inferTypes(FileInput fileInput) { | |||
TrivialTypeInferenceVisitor trivialTypeInferenceVisitor = new TrivialTypeInferenceVisitor(projectLevelTypeTable, pythonFile, fullyQualifiedModuleName); | |||
WildcardImportVisitor wildcardImportVisitor = new WildcardImportVisitor(projectLevelTypeTable); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this need to be its dedicated visitor?
I know we're going for a naive implementation, but I think it's still sensible to assume that we don't want the following resolution:
foo()
from lib import * # contains foo
I'm under the impression that relying on the main visit of TrivialTypeInferenceVisitor
should be enough here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The TrivialTypeInferenceVisistor
is enough (initially that's what we did). Our thought was that if it is moved to its own visitor, it is easier to rip it out when we eventually will do that. But we didn't think of the example you provided
ecf4705
to
82abc6d
Compare
82abc6d
to
beaa712
Compare
Quality Gate passedIssues Measures |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos on the clear tests (well documenting the limitations) and the clear separation of commits (even if I didn't notice it initially, sorry about that!).
LGTM.
assertThat(fooExpr.typeV2()).isInstanceOf(FunctionType.class); | ||
assertThat(importedFooExpr.typeV2()).isInstanceOf(FunctionType.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add an assertion checking whether these are the same objects?
import mod2 | ||
(foo, mod1.foo, mod2.foo) | ||
"""), | ||
// foo should be mod2.foo, not mod1.foo. Since wildcard imports are only assigned to names without a symbol, foo will be equal to mod1.foo. See SONARPY-2357 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good! I think this is a reasonable behavior for now.
As a nitpick, I'd rename the Jira ticket to something a bit more explicit/neutral (Something like: Support edge cases of wildcard imports resolution
?)
@@ -3124,4 +3262,25 @@ private static Statement lastStatement(StatementList statementList) { | |||
List<Statement> statements = statementList.statements(); | |||
return statements.get(statements.size() - 1); | |||
} | |||
|
|||
private static class TestProject { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a pretty neat construct!
I'm wondering if it wouldn't make more sense for this to be in a different test category though (either ProjectLevelSymbolTableTest
or ProjectLevelTypeTableTest
, or even a new CrossFileTypeInferenceTest
dedicated to tests focused on import resolution.
We probably can keep this here for now though.
SONARPY-2310