basedmypy
basedmypy copied to clipboard
Warn on assignments of functions to classes
Needs some more thought, but:
Well
class A:
a: Callable[[int], str] = lambda x: ""
A().a(1) # no type error
So
from __future__ import annotations
class A:
a: Callable[[int], str] = lambda x: "" # E: A function on a class will become a method. [function-breaks-callable]
# N: Did you want "ClassVar[FunctionType]"/"Final[FunctionType]" instead?
b: Callable[[A], str] = some_callable # E: Some callable could be a function, externally verify it's not, or use "FunctionType" [possible-function]
c: FunctionType[[int], str] # ok
def __init__(self):
self.a = lambda x: ""
self.c = lambda x: ""
A.a = lambda x: "" # E: A function on a class will become a method. [?]
# N: Did you want "FunctionType" instead?
- related to #617