Skip to content

attrs plugin crashes with order comparison methods #22290

Open

Description

@AA-Turner

Crash Report

The attrs plugin crashes when processing a class twice.

attrs defaults to order=False for define/frozen, but mypy synthesises ordering methods when the order parameter is omitted from the decorator. Reprocessing then collides with the annotated attribute in the class body.

The repro below is slightly contrived, the real case was mypy processing the same class twice due to circular imports.

Traceback

t.py: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 2.4.0
Traceback (most recent call last):
  File ".../bin/mypy", line 12, in <module>
    sys.exit(console_entry())
  File "mypy/build.py", line 3094, in wrap_context
AssertionError: FuncDef:5(
  __lt__
  Args(
    Var:nil(self)
    Var:nil(other))
  def [_AT] (self: _AT, other: _AT) -> bool
  Block:-1(
    PassStmt:-1()))

t.py: note: use --pdb to drop into pdb

To Reproduce

uvx --with attrs mypy --show-traceback t.py

import attrs

@attrs.define
@attrs.frozen
class C:
    __lt__: int

Your Environment

  • Mypy version used: 2.4.0
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.12
  • Operating system and version: linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions