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-1801 infer type of subscription expression when it is a class with generic type #1776

Open
wants to merge 1 commit into
base: rnd/type-inference-engine-specification
Choose a base branch
from

Conversation

maksim-grebeniuk-sonarsource
Copy link
Contributor

No description provided.

Copy link

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure about keeping this logic in the Tree itself despite the fact we did that in the previous implementation. I think it would make sense to do it during the visit of TypeInferenceV2 to centralize the places where types are set (I realize it's actually quite difficult to know where a type is set in the current implementation, as it can happen in many places...).

I'm also unsure about the edge cases we could face with this. Ideally it could be nice to have an extra test for a possible edge case that is actually not generic (if it exists0>

@@ -77,4 +79,13 @@ public List<Tree> computeChildren() {
public Kind getKind() {
return Kind.SUBSCRIPTION;
}

@Override
public PythonType typeV2() {

Choose a reason for hiding this comment

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

Instinctively, I believe typeV2() should ideally only be a getter for types.
I believe the logic of this method would make more sense in TypeInferenceV2 itself.

I see in the previous implementation this was done in CallExpressionImpl directly, using a similar logic, though. It did have some checks to ensure we were indeed dealing with a generic type, I think it would make sense to have it as well to avoid edge cases (I guess you could create a class where the class object itself has a __getitem__ method...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants