Open
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_content
This 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).