Skip to content

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.

3 participants