I am reusing a popular c++ idiom where a class contains a static dictionary of class instances:
class Zzz:
elements = {}
def __init__(self, name):
self._name = name
Zzz.elements[name] = self
@staticmethod
def list_instances():
for k in Zzz.elements.items():
print(k)
It worked fine until I added type annotation, now python complains that Zzz is an unknown type: NameError: name 'Zzz' is not defined
from typing import Dict
class Zzz:
elements: Dict[str,Zzz] = {} <---- here