-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
PEP 681: Descriptor fields #2369
Conversation
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.
Thanks. A few copyediting fixes and improvements.
Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
@JelleZijlstra there was a Typing SIG email from Carl Meyer today that looks like it will result in some changes to transform_descriptor_types. Should we hold off on completing this PR? |
Up to you. There's no harm in having more PRs later. I'm happy to merge this now if you would like me to. |
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.
LGTM, thanks @debonte . This is good to merge if you are happy with it; my suggestion would be that it is probably best to just merge this now that we've all approved, so they go live now as a discrete commit, and then open a followup PR with additional changes. Then, its easier for both you and us to focus on the new changes, and keeping things in scope.
@JelleZijlstra, can you please merge this? I'll submit another PR to addresss Carl Meyer's feedback as CAM-Gerlach suggested above. |
Improves support for classes with fields that are descriptors. Setting a new
dataclass_transform
parameter namedtransform_descriptor_types
toTrue
indicates that__init__
parameters corresponding to descriptor fields have the type of the descriptor’s__set__
value parameter rather than the descriptor type.In the following example, type checkers would understand that the
quantity_on_hand
parameter of the__init__
method onInventoryItem
is of typeint | None
rather thanDescriptor[int]
.This change was driven by a need in SQLAlchemy as discussed at microsoft/pyright#2958.
A reference implementation is available in Pyright 1.1.222 and Pylance 2022.2.3.