Skip to content
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

Consolidate descriptor handling in checkmember.py #18831

Merged
merged 4 commits into from
Mar 24, 2025

Conversation

ilevkivskyi
Copy link
Member

@ilevkivskyi ilevkivskyi commented Mar 22, 2025

This is not a pure refactoring, but almost. Right now we are in a weird situation where we have two inconsistencies:

  • __set__() is handled in checker.py while __get__() is handled in checkmember.py
  • rules for when to use binder are slightly different between descriptors and settable properties.

This PR fixes these two things. As a nice bonus we should get free support for unions in __set__().

This comment has been minimized.

@ilevkivskyi
Copy link
Member Author

Hm, couple new errors in dd-trace-py raises an interesting question, whether we need to invoke descriptors when they appear as a protocol attribute? Although they are technically defined in the class body, IIUC the intention for them is to be instance variables. Normally we skip descriptors if the variable is implicit (i.e. was set on self), but there is no such thing in protocols.

I will try this later today, just to check the possible fallout.

This comment has been minimized.

Copy link
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

kornia (https://github.com/kornia/kornia)
- kornia/augmentation/container/augment.py:449: error: Unsupported right operand type for in ("list[DataKey] | None")  [operator]
- kornia/augmentation/container/augment.py:450: error: Item "None" of "list[DataKey] | None" has no attribute "index"  [union-attr]
+ kornia/augmentation/container/augment.py:321: error: Unused "type: ignore" comment  [unused-ignore]
+ kornia/augmentation/container/augment.py:323: error: Unused "type: ignore" comment  [unused-ignore]
+ kornia/augmentation/container/augment.py:443: error: Unused "type: ignore" comment  [unused-ignore]
+ kornia/augmentation/container/augment.py:445: error: Unused "type: ignore" comment  [unused-ignore]

steam.py (https://github.com/Gobot1234/steam.py)
+ steam/state.py:2427: error: Argument "targetid" to "AddReactionRequest" has incompatible type "int | _ReadOnlyProto[int]"; expected "int"  [arg-type]
+ steam/state.py:2440: error: Argument "targetid" to "GetReactionsRequest" has incompatible type "int | _ReadOnlyProto[int]"; expected "int"  [arg-type]

dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/internal/wrapping/__init__.py:301: error: Unused "type: ignore" comment  [unused-ignore]

@ilevkivskyi
Copy link
Member Author

OK, this question reminded me a discussion we had a while ago about what to do for variables annotated with Callable, when should we bind self in them? So I essentially re-use the same logic we agreed on that (which is btw essentially the same story as descriptors are involved under the hood there).

I am happy with the primer, so I will be merging this today/tomorrow unless there are objections.

@ilevkivskyi ilevkivskyi merged commit df9ddfc into python:master Mar 24, 2025
18 checks passed
@ilevkivskyi ilevkivskyi deleted the move-descriptor-set branch March 24, 2025 20:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant