-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Improve typing for ast nodes which represent assignment behaviour #9326
Improve typing for ast nodes which represent assignment behaviour #9326
Conversation
This comment has been minimized.
This comment has been minimized.
stdlib/_ast.pyi
Outdated
@@ -98,20 +98,20 @@ class Delete(stmt): | |||
class Assign(stmt): | |||
if sys.version_info >= (3, 10): | |||
__match_args__ = ("targets", "value", "type_comment") | |||
targets: list[expr] | |||
targets: list[Tuple | Name | Attribute | Subscript | Starred] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing List
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd definitely prefer it if we left this one as it is. It feels especially problematic due to list
invariance, as we can see from the mypy_primer
output. The current annotation is more ergonomic, even if it's slightly less precise. The situation will get worse if we add better __init__
methods for ast
nodes, as proposed in #8378
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK I will revert this change. I agree with @AlexWaygood, the current state is better from ergonomics standpoint.
Btw, as I am working a lot with ast
module lately (writing something similar to https://www.archunit.org/ but for Python), I can take on the #8378 after this one is done and in general I'd like to contribute to improvement of typing for ast
module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I lean towards not changing this at all: I think it's better to reflect the declared ASDL types directly instead of narrowing things down manually. |
I feel like I'm much more in favour of the changes to |
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with this to go in, now that it's restricted to only AugAssign
, AnnAssign
and NamedExpr
. I think it's a useful change.
Closes #9287.
I also decided to type ast.Assign. The new hint for it is still less broad then
expr