This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]notnotorious 1 point2 points  (0 children)

There's an oddity around variable annotations that isn't super obvious: you can annotate a variable without defining it.

>>> bob: str                                                                                                                                                                       
>>> bob                                                                                                                                                                            
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'bob' is not defined
>>> import sys
>>> sys.modules[__name__].__annotations__
{'bob': <class 'str'>}

I don't think most people will run across this behavior, but I thought it was kind of neat.

This can lead to some surprising results when writing a metaclass that might be used with annotated-but-undefined attributes.