Extend allowed dunder methods (PLW3201)
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 458
Description
Opened as a followup to discussion at #9706.
Kudos to @AlexWaygood for scraping all dunders from CPython:
> This is the set of dunders that were surfaced in my script and are not currently listed by ruff as excluded from this rule:
>
> ```
> ['__cmp__',
> '__conform__',
> '__getinitargs__',
> '__getitem_inner__',
> '__getslice__',
> '__import__',
> '__isabstractmethod__',
> '__members__',
> '__newobj__',
> '__newobj_ex__',
> '__nonzero__',
> '__parameters__',
> '__rich__',
> '__rich_console__',
> '__rich_measure__',
> '__rich_repr__',
> '__setslice__',
> '__signature__',
> '__tp_del__',
> '__typing_is_unpacked_typevartuple__',
> '__typing_unpacked_tuple_args__',
> '__unicode__',
> '__version__',
> '__wrapped__']
> ```
>
> 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 `__rich_*__` ones are because I have `rich` installed in a venv inside my cpython local clone, I think?
>
> I like that the script surfaced `__import__` -- that's the literal definition of Python's `import` statement right there 😄
In my opinion, it would be useful to add `__wrapped__` , `__isabstractmethod__` and `__signature__` to the list in case one wants to define those as properties (it's a niche use case though), especially since `__class__` is in the list.
`__rich_*__` should definitely be supported, a lot of critical tools & libraries have integrations with rich (including pip or Pydantic).
Some external libraries also implement their own dunders, such as pyarrow's [`__arrow_array__` used in pandas](https://github.com/pandas-dev/pandas/blob/9b95e4596c5d47b5dcc3cbedf143023475930595/pandas/core/arrays/string_.py#L429) or [`__attrs_post_init__` from attrs](https://www.attrs.org/en/stable/init.html#post-init) (among others) which I can see being supported now.
How should we research and collect them? What criteria should we have?
Contributor guide
Research direction
Start with the PLW3201 implementation and the discussion referenced in #9706, then review the listed CPython, Rich, pyarrow, pandas, and attrs dunders. Define evidence-based criteria for supporting names such as __wrapped__, __rich_*__, __arrow_array__, and __attrs_post_init__, and document which additions the rule should accept.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- devtools, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100