How do I use "with" as a key in a TypedDict?
Question:
Answers:
with
is a keyword in Python for Context Managers. Have a look here: https://realpython.com/python-with-statement/
You won’t be able to use the declarative syntax, as with
(being a hard keyword defined by the grammar) is not a valid identifier; use the functional syntax instead.
Operation = TypedDict('Operation', {'uses': str, 'with': Optional[ActionCheckout]})
This is specifically addressed in the documentation:
The functional syntax should also be used when any of the keys are not valid identifiers, for example because they are keywords
with
is a keyword in Python for Context Managers. Have a look here: https://realpython.com/python-with-statement/
You won’t be able to use the declarative syntax, as with
(being a hard keyword defined by the grammar) is not a valid identifier; use the functional syntax instead.
Operation = TypedDict('Operation', {'uses': str, 'with': Optional[ActionCheckout]})
This is specifically addressed in the documentation:
The functional syntax should also be used when any of the keys are not valid identifiers, for example because they are keywords