-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[pylint
] Add __mro_entries__
to known dunder methods (PLW3201
)
#9706
Conversation
Yes, I actually need this.
__mro_entries__
to known dunder methods
__mro_entries__
to known dunder methodspylint
] Add __mro_entries__
to known dunder methods
|
pylint
] Add __mro_entries__
to known dunder methodspylint
] Add __mro_entries__
to known dunder methods (PLW3201
)
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!
I ran a small script to find all the dunders defined in CPython (not thoroughly tested; it might have bugs): import ast, re, pathlib, pprint
is_dunder = re.compile(r"__[^_](.+[^_])?__").fullmatch
class DunderCollector(ast.NodeVisitor):
def visit_FunctionDef(self, node):
if is_dunder(node.name):
dunders.add(node.name)
visit_AsyncFunctionDef = visit_FunctionDef
dunders = set()
for path in pathlib.Path(".").rglob("*.py"):
try:
source = path.read_text()
except Exception as e:
print(f"Skipping {path} due to {e}")
continue
try:
tree = ast.parse(tree)
except Exception as e:
print(f"Skipping {path} due to {e}")
continue
DunderCollector().visit(tree)
pprint.pprint(sorted(dunders)) Run it from the CPython repo root, and it gives these results:
Some of those are internal implementation details that we definitely shouldn't add to the list of known dunder methods, in my opinion ( |
A community project I maintain has a spreadsheet with a curated list of all* 224 dunders (iirc it includes docs too) 👍 *excluding a few false positives like |
having now done this, I think there are 0 true positives (that are not already listed by ruff) in that list my script produced :) This is the set of dunders that were surfaced in my script and are not currently listed by ruff as excluded from this rule:
Most of them seem to be definitions in tests, internal implementation details that are undocumented, and/or leftovers from Python 2 that still haven't been cleaned up. The I like that the script surfaced |
It would be useful to add |
Let's move the discussion to #9716. |
Yes, I actually need this dunder in my project.
Summary
This change adds
__mro_entries__
to the list of known dunder methods.Test Plan
8893a3c.