Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spurious messages for functions as instance attributes #11776

Closed
inducer opened this issue Dec 17, 2021 · 1 comment
Closed

Spurious messages for functions as instance attributes #11776

inducer opened this issue Dec 17, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@inducer
Copy link

inducer commented Dec 17, 2021

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.

@inducer inducer added the bug mypy got something wrong label Dec 17, 2021
@hauntsaninja
Copy link
Collaborator

Thanks, duplicate of #5485

See also #11571 and #10548

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants