-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)topic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
Description
It seems Walrus operators (in Python 3.8+) are not recognised by mypy when used in initialising a dictionary of a class attribute. Here is a test code.
class TryWalrus:
CKEY = {
'KY': (p:='a_'),
'ANOTHER': p+'content',
}
print(TryWalrus.CKEY['ANOTHER']) # => a_contentThis outputs the following:
$ mypy try_walrus.py
try_walrus.py:4: error: Name 'p' is not defined
Found 1 error in 1 file (checked 1 source file)
If the variable CKEY is out of the class definition, i.e. if directly in Main, it does not raise an error.
I tested it with Python 3.8.1 and mypy version 0.770+dev.8888b1aedf6d4ba543ae12f538f190ce5e65c20d (yesterday's head).
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-pep-572PEP 572 (walrus operator)PEP 572 (walrus operator)topic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly