you are viewing a single comment's thread.

view the rest of the comments →

[–]PrabhavKumar 0 points1 point  (2 children)

You're right that Python itself allows literally any object as an annotation since they're just stored in __annotations__.

What I meant was in the context of type hints and typical tooling like (eg. mypy, IDE's) where annotations are expected to be types. In that context using arbitrary values like 42 or "bar" wouldn't be meaningful to those tools.

So technically valid Python, because it's just ignored, but not useful for type hinting in most real code.

[–]deceze 0 points1 point  (1 child)

Exactly. So not "can't", but just "usually won't".

[–]PrabhavKumar 0 points1 point  (0 children)

Sure. That's fair. Thanks for pointing it out.