-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)
Description
Consider this code with truthy-bool
:
class A:
def method(self) -> bool:
return True # whatever
if (a := A()) and a.method():
print(a)
It will output:
» mypy ex.py --enable-error-code=truthy-bool
ex.py:6: error: "ex.a" has type "A" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
ex.py:6: error: "ex.A" returns "A" which does not implement __bool__ or __len__ so it could always be true in boolean context [truthy-bool]
Two questions:
- Why two errors?
- Maybe we should skip this rule completely for
(:=) and ...
, becausea
is not really the main thing we check here?
CC @ikonst
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)