Skip to content

Infer type for partial generic type from assignment #8036

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

Merged
merged 4 commits into from
Nov 29, 2019
Merged

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Nov 29, 2019

Code like this no longer requires a type annotation:

a = []
if foo():
    a = [1]

Work towards #1055.

Code like this no longer requires a type annotation:

```
a = []
if foo():
    a = [1]
```
Copy link
Member

@ilevkivskyi ilevkivskyi left a comment

Choose a reason for hiding this comment

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

Thanks! Just one comment, I think case of self.x is important.

if foo():
x = [1] # Infer List[int] as type of 'x'
"""
if (isinstance(lvalue, NameExpr)
Copy link
Member

Choose a reason for hiding this comment

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

Should this actually be a NameExpr or RefExpr is fine? I am thinking about self.x = [], please add tests if yes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Partial types are not properly supported with attributes in general, so this is consistent with how things work elsewhere.

@JukkaL JukkaL merged commit 7e7eedd into master Nov 29, 2019
@gvanrossum gvanrossum deleted the partial-assign branch August 26, 2020 21:25
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