-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[red-knot] Descriptor protocol #15966
Comments
An important case to consider here that isn't shown in the example in summary is where the |
Yes, thanks. This is already covered in the provisional tests (#15972). |
## Summary This is a first step towards creating a test suite for [descriptors](https://docs.python.org/3/howto/descriptor.html). It does not (yet) aim to be exhaustive. relevant ticket: #15966 ## Test Plan Compared desired behavior with the runtime behavior and the behavior of existing type checkers. --------- Co-authored-by: Mike Perlov <[email protected]>
@carljm @sharkdp sorry, for delay Here is my thinking, proposed plan & rough design. Guiding principles I've used:
Design
Obviously there are going to be a lot of minute details in actual implementation, but overall it feels like descriptors do not introduce any special needs really. PlanThe plan, is to start with known classes and avoid bothering with full inference of descriptor dunder method signatures. Implement the non-data descriptors first, using the most popular builtins. Then expand to set only data descriptor and build-up support for known descriptor classes. Then tackle everything else. Assuming red_knot is targeting "an average" python user, I'd suggest implementing in the following order based on frequency of use:
PS. I can theoretically augment this with samples for each step, but this can also be done in individual issues. |
We need to understand the descriptor protocol in order to infer proper types for attribute accesses like in this simple example:
References: Python Documentation: Descriptor Guide
part of: #14164
The text was updated successfully, but these errors were encountered: