Skip to content

Refactor operator method access and protocol checks to use checkmember.py #5136

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

Closed
Tracked by #5119
ilevkivskyi opened this issue Jun 2, 2018 · 2 comments · Fixed by #19250
Closed
Tracked by #5119

Refactor operator method access and protocol checks to use checkmember.py #5136

ilevkivskyi opened this issue Jun 2, 2018 · 2 comments · Fixed by #19250

Comments

@ilevkivskyi
Copy link
Member

Currently code that checks access to dunder operator methods duplicates code in checkmember.py. Apart from code duplication, the code for operators is more simplistic and doesn't cover some corner cases. A similar situation is with accessing attributes for protocol checks.

The common pattern in both cases is that we need almost the same logic as in checkmember.py, but with some steps skipped and error reporting suppressed.

@JukkaL
Copy link
Collaborator

JukkaL commented Jun 4, 2018

One concrete difference is that operator methods on type objects (as opposed to instances) have different semantics -- they can't generally be defined as class/static methods (and there's __class_getitem__ in Python 3.7).

@Michael0x2a
Copy link
Collaborator

Just to add some extra details/clues: I tried removing that call in my recent operators refactor, and it ended up breaking the pythoneval.testMetaclassOpAccessAny test case to fail -- I added a TODO about this to the relevant section of the code.

ilevkivskyi added a commit that referenced this issue Jun 9, 2025
Fixes #5136
Fixes #5491

This is a fifth "major" PR toward
#7724. Although it would be
impractical to move all the operator special-casing to `checkmember.py`,
this does two things:
* Removes known inconsistencies in operator handling
* Adds a much more complete `has_operator()` helper that can be a
starting point for future performance optimizations
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants