If I have a key in a dictionary with an invalid identifier, such as A(2)
. How can I create a TypedDict
with this field?
E.g
from typing import TypedDict
class RandomAlphabet(TypedDict):
A(2): str
is not valid Python code, resulting in the error:
SyntaxError: illegal target for annotation
The same problem is with reserved keywords:
class RandomAlphabet(TypedDict):
return: str
throws:
SyntaxError: invalid syntax
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…