-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
When linting this program with mypy:
from typing import SupportsInt
class Bar:
def __int__(self):
return 1
def foo(a: SupportsInt):
return int(a)
foo('1')
foo(True)
foo(1)
foo(1.1)
foo(Bar())
I got the following errors:
test.py:12: error: Argument 1 to "foo" has incompatible type "str"; expected "SupportsInt"
test.py:16: error: Argument 1 to "foo" has incompatible type "Bar"; expected "SupportsInt"
I was expecting that anything accepted but int()
would be accepted by something hinting for SupportsInt. Is my expectation wrong or is this a bug?
If my expectations are wrong, how would I create the same signature as int()
?