You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to store a lambda in an object and then call it. Mypy doesn't like it.
from typing import Callable
class A:
f: Callable[[bool], bool]
def __init__(self, f):
self.f = f
def foo(b: bool) -> bool:
return b
a = A(foo)
print(a.f(True))
Running:
dhcp-172-31-207-247:~ ezyang$ python3.7 bb.py
True
dhcp-172-31-207-247:~ ezyang$ mypy --version
mypy 0.660
dhcp-172-31-207-247:~ ezyang$ mypy bb.py
bb.py:12: error: Invalid self argument "A" to attribute function "f" with type "Callable[[bool], bool]"
bb.py:12: error: Too many arguments
(The reason I want to do this is because the object is a dataclass and I'm not exactly sure how well inheritance works with dataclasses, so I thought, maybe I can keep things simple by just storing callables on the object.)
The text was updated successfully, but these errors were encountered:
I wanted to store a lambda in an object and then call it. Mypy doesn't like it.
Running:
(The reason I want to do this is because the object is a dataclass and I'm not exactly sure how well inheritance works with dataclasses, so I thought, maybe I can keep things simple by just storing callables on the object.)
The text was updated successfully, but these errors were encountered: