-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
WIP: adds better namedtuple
semantic analyzer
#11206
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
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This PR would also help us a lot: python/typeshed#6080 Since we now typecheck |
The best practice is to match `typename` with variable name. For example, `mypy` reports any other usages as errors: python/mypy#11206 (comment)
The best practice is to match `typename` with variable name. For example, `mypy` reports any other usages as errors: python/mypy#11206 (comment)
This comment has been minimized.
This comment has been minimized.
The best practice is to match `typename` with variable name. For example, `mypy` reports any other usages as errors: python/mypy#11206 (comment)
I am working on new `mypy` feature and it identified a problem with your `namedtuple` definitions. python/mypy#11206 (comment) By standard first string arg should match variable name.
I finally have the time to continue my work! All PRs that I needed: python/typeshed#6080 / #11303 / #11162 are merged! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I am working on new `mypy` feature and it identified a problem with your `namedtuple` definitions. python/mypy#11206 (comment) By standard first string arg should match variable name.
This comment has been minimized.
This comment has been minimized.
6 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
3 similar comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
While working on python/mypy#11206 I found that `Regspec` definition is not ideal. It is recommended to use the same string name, as variable name. For example, it affects how `pickle` works. Related trailofbits#2501 Related trailofbits@6e036f3
While working on python/mypy#11206 I found that `Regspec` definition is not ideal. It is recommended to use the same string name, as variable name. For example, it affects how `pickle` works. Related #2501 Related 6e036f3
You might use |
@97littleleaf11 thank you! Can you please be more specific? 🙂 |
@sobolevn You can just replace |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: pandas (https://github.com/pandas-dev/pandas)
+ pandas/core/frame.py:1402: error: Unused "type: ignore" comment
+ pandas/core/frame.py:1403: error: "namedtuple()" expects a string literal as the typename argument [misc]
|
Awesome, thank you, @97littleleaf11 I will add more tests for |
This is almost a complete rewrite of inline
NamedTuple
andnamedtuple
semantic analyzer.Changelog:
NamedTuple
now supports**kwargs
as it shouldNamedTuple
andnamedtuple
now have better validation for fields: keywords, underscores, duplication: basically the same ascollections.namedtuple
does at runtimenamedtuple
now supportsrename
argument (it actually renames invalid fields)NamedTuple()
andnamedtuple()
calls during typechecking, this allows us to simplify the setupbytes
are valid arguments onpython3
NamedTuple
andnamedtuple
now support named arguments as they shouldsemanal.py
does not raise any namedtuple-expr-related errorscollections.namedtuple
, added""
everywhereThis is still WIP, but I've wrote several tests for this in
testsemanal.py
. They are passing. Andself
check also passes.I can continue to work on this after #11162 is merged or rejected. Because I need better typing fixtures for
NamedTuple
type.Closes #11047