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-1796 Infer types for set, dict and tuple literals #1773

Conversation

guillaume-dequenne-sonarsource
Copy link
Contributor

Tuple content type is inferred immediately if (and unique) available as tuple are immutables.
This should be seen as a baby step/low-hanging fruit. I'd expect a dedicated effort to tackle any more complex case.

Also, this PR does not deal with display name/representation of those generic types.

Not 100% related to the ticket, but I also took the opportunity to add some missing test for some already covered literal types (str, numeric literals and None).

Base automatically changed from SONARPY-1794 to rnd/type-inference-engine-specification April 25, 2024 12:47
@guillaume-dequenne-sonarsource guillaume-dequenne-sonarsource marked this pull request as ready for review April 25, 2024 13:09
}
ModuleType builtins = this.projectLevelTypeTable.getModule(BUILTINS);
PythonType tupleType = builtins.resolveMember("tuple").orElse(PythonType.UNKNOWN);
((TupleImpl) tuple).typeV2(new ObjectType(tupleType, attributes, List.of()));

Choose a reason for hiding this comment

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

using List.of() could be dangerous since it is immutable. I'd prefer to use array lists instead

Copy link
Contributor

Choose a reason for hiding this comment

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

LGTM

Copy link

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