I'm guessing this is documented somewhere and has been discussed before, and I will close this question if someone finds a duplicate.
In python 3.6 I can enter the line
foo: "bar"
or
x: 1.2345
and this appears to be valid syntax. That is, any set of characters formatted like a variable name followed by a colon then some object does not raise an error. I've been using python for quite a while so this was really surprising to me. What is the interpreter seeing here? What is this for?
I came across this when reading about python3.7
and the new @dataclass
decorator; I noticed the examples use the syntax
@dataclass
class Color:
lightness: float = 0.5
hue: float
saturation: float
and assumed this loose key: value
syntax was new. Evidently not.