When type annotating a variable of type dict, typically you'd annotate it like this:
numeralToInteger: dict[str, int] = {...}
However I rewrote this using a colon instead of a comma:
numeralToInteger: dict[str : int] = {...}
And this also works, no SyntaxError or NameError is raised.
Upon inspecting the __annotations__
global variable:
colon: dict[str : int] = {...}
comma: dict[str, int] = {...}
print(__annotations__)
The output is:
{'colon': dict[slice(<class 'str'>, <class 'int'>, None)],
'comma': dict[str, int]}
So the colon gets treated as a slice object and the comma as a normal type hint.
Should I use the colon with dict types or should I stick with using a comma?
I am using Python version 3.10.1.