-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Add support for attrs.fields
#15021
Add support for attrs.fields
#15021
Conversation
This comment has been minimized.
This comment has been minimized.
Great feedback. Looks like I'll need to switch to |
This comment has been minimized.
This comment has been minimized.
I'll try to take a look tomorrow. |
@hauntsaninja Hello, I know you mentioned the plugin subsystem isn't really your thing, but could you recommend someone else to help review this? <3 |
I can review this, please fix the merge conflict first though. |
This comment has been minimized.
This comment has been minimized.
@JelleZijlstra Thank you! Done. |
This comment has been minimized.
This comment has been minimized.
Co-authored-by: Ilya Priven <[email protected]>
for more information, see https://pre-commit.ci
This comment has been minimized.
This comment has been minimized.
I don't think this PR will handle unions properly, but I consider this an advanced use case and can tackle it in a future PR. |
This comment has been minimized.
This comment has been minimized.
Diff from mypy_primer, showing the effect of this PR on open source code: graphql-core (https://github.com/graphql-python/graphql-core) got 1.05x slower (282.3s -> 297.1s)
|
Add support for attrs.fields python/mypy#15021
I don't believe that inferring a fixed-length tuple here is actually that useful. In actual uses of
now reveals |
I'm pretty bullish on this change since it unlocks very interesting stuff, both by itself and down the line, such as python-attrs/attrs#1144. That said, maybe we can stick a custom |
This reverts commit 391ed85. The use of a Union item type for `attr.Attribute` would likely be more useful to callsites of `attr.fields` - otherwise this currently results in inferring `builtins.object` in many cases where we treat the fields as a variable-length tuple, rather than a fixed-length one. Applications of the fixed-length tuple seem limited since you would need to access it by index. @Tinche as the original author of the commit.
Yeah, I think this could work. @jhance What do you think? |
I am more interested in basic cases continuing to work than supporting more interesting advanced cases. I am not sure how you would add an extra I'm happy to have this feature if it doesn't break basic use cases, but resolving the breakage here is blocking release for us. I am going to include the revert in the release branch for 1.4.0, but wait on reverting in master until we have a plan for what we want to do here. |
This reverts commit 391ed85. The use of a Union item type for `attr.Attribute` would likely be more useful to callsites of `attr.fields` - otherwise this currently results in inferring `builtins.object` in many cases where we treat the fields as a variable-length tuple, rather than a fixed-length one. Applications of the fixed-length tuple seem limited since you would need to access it by index. @Tinche as the original author of the commit.
This reverts commit 391ed85.
Howdy Mypy friends.
This add support for
attrs.fields
, which is a nicer way of accessing the attrs magic attribute.