Skip to content

Don't add ordering methods to attrs.define and attrs.frozen classes by default - #22305

Closed
NavpreetSSidhu wants to merge 1 commit into
python:masterfrom
NavpreetSSidhu:attrs-define-order
Closed

NavpreetSSidhu wants to merge 1 commit into
python:masterfrom
NavpreetSSidhu:attrs-define-order

Conversation

@NavpreetSSidhu

@NavpreetSSidhu NavpreetSSidhu commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #22290

attrs.define, attrs.mutable and attrs.frozen (and their attr. aliases) default to order=False, but the plugin derived order from eq for them like it does for attr.s, so it added __lt__/__le__/__gt__/__ge__ to every such class. Comparing two instances with < was accepted even though it fails at runtime.

This also caused the crash in the issue: the synthesized __lt__ replaced the __lt__ attribute, and the next pass over the class hit assert isinstance(node, Var).

The new-style makers now pass order_default=False; an explicit order=True still adds the methods. testAttrsIncrementalArguments relied on the old default for its Frozen class, so it now uses @attrs.frozen(order=True).

Added testAttrsDefineNoOrderByDefault and testAttrsDefineFrozenAttributeNamedLikeOrderMethod; both fail on master and pass with this change.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@ilevkivskyi ilevkivskyi closed this Nov 2, 2026
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.

attrs plugin crashes with order comparison methods

2 participants