Skip to content

1.9 Regression: __hash__ method in attrs class is ignored #17015

Closed

Description

@Hnasar

Bug Report
mypy is ignoring a manually-written __hash__ method in an attrs class.
Bisect points to 91be285 causing the regression. cc @Tinche
Possibly reported already in a comment here? #16556 (comment)

To Reproduce

import attrs
from typing import reveal_type

@attrs.define()
class A():
    name: str = attrs.field()
    def __hash__(self) -> int:
        return hash(self.name)

reveal_type(A.__hash__)

Expected Behavior

$ py -m mypy --strict foo.py  # 1.8
foo.py:10: note: Revealed type is "def (self: foo.A) -> builtins.int"
$ py foo.py
Runtime type is 'function'

Actual Behavior

$ py -m mypy --strict foo.py  # 1.9
foo.py:10: note: Revealed type is "None"
$ py foo.py
Runtime type is 'function'

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags: n/a
  • Python version used: 3.12
  • attrs version: 23.2.0

Activity

  1. Tinche commented on Mar 11, 2024

    @Tinche
    Contributor

    I'll take this.

  2. added 6 commits that reference this issue on Mar 11, 2024
    73bf317
    00c0ef7
    93502ae
    2349743
    a663346
    d40909e
  3. added a commit that references this issue on Mar 15, 2024
    31dc503
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