Skip to content
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-2316 Resolve field members of a ClassType #2163

Merged
merged 2 commits into from
Nov 20, 2024

Conversation

maksim-grebeniuk-sonarsource
Copy link
Contributor

@maksim-grebeniuk-sonarsource maksim-grebeniuk-sonarsource commented Nov 18, 2024

Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
I left clarification questions and a few comments. Well done!

@@ -70,6 +70,13 @@ public SymbolImpl(String name, @Nullable String fullyQualifiedName) {
this.kind = Kind.OTHER;
}

public SymbolImpl(String name, @Nullable String fullyQualifiedName, @Nullable String annotatedTypeName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor you can slightly modify the constructor above to call the new one you ve created.

  public SymbolImpl(String name, @Nullable String fullyQualifiedName) {
    this(name, fullyQualifiedName, null);
  }

@@ -70,6 +70,13 @@ public SymbolImpl(String name, @Nullable String fullyQualifiedName) {
this.kind = Kind.OTHER;
}

public SymbolImpl(String name, @Nullable String fullyQualifiedName, @Nullable String annotatedTypeName) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question It seems there are only a few unit tests for this class. May be you can add a unit test in SymbolImplTest to test the constructor you have created?

Comment on lines 462 to 464
scan(assignmentStatement.assignedValue());
scan(assignmentStatement.annotation());
scan(assignmentStatement.variable());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any reason you don't call super? Tests in TypeInferenceV2Test are still green if I use the call to super

Suggested change
scan(assignmentStatement.assignedValue());
scan(assignmentStatement.annotation());
scan(assignmentStatement.variable());
super.visitAnnotatedAssignment(assignmentStatement);

.filter(NameImpl.class::isInstance)
.map(NameImpl.class::cast)
.ifPresent(lhsName -> {
if (currentType() instanceof ClassType) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question this line is to check that you are in a class definition right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed

Comment on lines 561 to 580
class A:
test = "hi"
test = True
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest that you update the test with type hint to ensure that the type of test Symbol is bool in the end.

Suggested change
class A:
test = "hi"
test = True
class A:
test : str = "hi"
test : bool = True

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test added

@@ -562,10 +631,13 @@ class B:
test = "hi"
class C(A, B):
pass
C.test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you have to remove the access to the field test everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

discussed

Copy link
Contributor

@thomas-serre-sonarsource thomas-serre-sonarsource left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@maksim-grebeniuk-sonarsource maksim-grebeniuk-sonarsource merged commit 2e55165 into master Nov 20, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants