Closed
Description
Given the following code in test.py
:
def bar() -> "FooClass":
list1 = [FooClass()]
list2 = [m for m in list1 if m.matches]
return list2[0]
class FooClass:
def __init__(self) -> None:
self.matches = True
Testing it with mypy --warn-return-any test.py
(mypy 0.550, Python 3.6.3) gives the following error:
test.py:4: warning: Returning Any from function declared to return "FooClass"
Any of the following "fixes" this error:
- Move
FooClass
declaration in front of the declaration ofbar()
- Remove the
m.matches
check inside the list comprehension - Remove --warn-return-any from the command line
- Adding
assert isinstance(list2[0], FooClass)
before the return
Metadata
Metadata
Assignees
Labels
No labels