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
Tried to write type stubs for lazy package. Lazy provides a descriptor that invokes the underlying method only once and caches the result in the instance.
The inferred type is <nothing>, so mypy crashes when checking expressions.
fromtypingimportAny, Generic, Callable, TypeVarT=TypeVar('T')
classlazy:
def__init__(self, func: Callable[[Any], T]) ->None: ...
def__get__(self, inst: Any, inst_cls: Any) ->T: ...
classHaystack:
@lazydefhasNeedles(self) ->bool:
# some expensive lookup we want to execute only oncereturnTruereveal_type(Haystack().hasNeedles)
# checking this expression crashesx=Haystack().hasNeedlesorTrue
<...>
note: Revealed type is '<nothing>'
<...>
version: 0.761
Traceback (most recent call last):
File "mypy/checkexpr.py", line 3645, in accept
File "mypy/nodes.py", line 1736, in accept
File "mypy/checkexpr.py", line 2029, in visit_op_expr
File "mypy/checkexpr.py", line 2662, in check_boolean_op
If lazy was defined as a function, type gets inferred correctly.
deflazy(func: Callable[[Any], T]) ->T: ...
note: Revealed type is 'builtins.bool*'
The text was updated successfully, but these errors were encountered:
This doesn't crash any more on master. Here's the output I get:
$ mypy t/t3.py
t/t3.py:7: error: A function returning TypeVar should receive at least one argument containing the same Typevar
t/t3.py:15: note: Revealed type is "<nothing>"
t/t3.py:18: error: Need type annotation for "x"
Found 2 errors in 1 file (checked 1 source file)
Tried to write type stubs for lazy package.
Lazy
provides a descriptor that invokes the underlying method only once and caches the result in the instance.The inferred type is
<nothing>
, so mypy crashes when checking expressions.If lazy was defined as a function, type gets inferred correctly.
The text was updated successfully, but these errors were encountered: