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

Class with attribute function thinks first argument is self #10353

Closed
spagh-eddie opened this issue Apr 22, 2021 · 1 comment
Closed

Class with attribute function thinks first argument is self #10353

spagh-eddie opened this issue Apr 22, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@spagh-eddie
Copy link

spagh-eddie commented Apr 22, 2021

Bug Report

I find this very similar to issue #5485.

I found myself using this flavor of idiom so as to not repeat myself when implementing comparison operations, etc.

To Reproduce

from operator import itemgetter

class A:
    id_getter = itemgetter('this', 'that', 'other')
    def __init__(self, d):
        self.d = d
    def __hash__(self) -> int:
        return hash(self.id_getter(self.d))

a = A({'this': 1, 'that': 2, 'other': 'a', 'extra': 'b'})
hash(a)

Expected Behavior

No error

Actual Behavior

$ mypy example.py
example.py:8: error: Too many arguments
Found 1 error in 1 file (checked 1 source file)

I tried to annotate id_getter: ClassVar[Callable[[Dict], Tuple[int, int, str]]] but just got back an additional error

examply.py:8: error: Invalid self argument "A" to attribute function "id_getter" with type "Callable[[Dict[Any, Any]], Tuple[Any, ...]]"

Your Environment

$ mypy --version
mypy 0.812

No flags or ini file.

@hauntsaninja
Copy link
Collaborator

Fixed by #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