Skip to content

Spurious messages for functions as instance attributes #11776

Closed
@inducer

Description

@inducer

Bug Report

Run this code:

from typing import Callable
from dataclasses import dataclass


@dataclass(frozen=True)
class Face:
    map_to_volume: Callable[[int], int]

f = Face(map_to_volume=lambda x: x)

f.map_to_volume(5)

through mypy 0.920 on Python 3.10 and get the following output:

$ mypy mypy-bug.py
mypy-bug.py:12: error: Invalid self argument "Face" to attribute function "map_to_volume" with type "Callable[[int], int]"
mypy-bug.py:12: error: "int" not callable
Found 2 errors in 1 file (checked 1 source file)

Expected Behavior

  • I'm surprised to see mypy complain about a self argument for map_to_volume. It's an instance attribute, not a class attribute, so it is not subject to method processing. Python seems to agree, no self argument is passed.
  • The message about int not being callable seems spurious: f.map_to_volume is not an int.

Your Environment

  • Mypy version used: 0.920
  • Mypy command-line flags: (none, see above)
  • Mypy configuration options from mypy.ini (and other config files): (none)
  • Python version used: 3.10
  • Operating system and version: Linux, Debian testing/unstable

x-ref: inducer/modepy#45, which tries to remove a type: ignore that was necessitated by #9975.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions