[issue43817] Add inspect.get_annotations()

Larry Hastings report at bugs.python.org
Wed Apr 21 06:16:32 EDT 2021


Larry Hastings <larry at hastings.org> added the comment:

> Are you saying the user would expect to be able to change __annotations__ my modifying the dict they get back?

As the docs are currently written, it's ambiguous.

> Is it ever the case that the user can modify __annotations__ through the dict that's returned? That is: does __annotations__ itself ever get returned?

Yes.  I could enumerate the cases in which that is true but I don't think it would shed light.  Suffice to say, as currently written, get_annotations() currently returns the original dict unmodified when it can, and returns a freshly-created dict when it can't.

> I think you'd either want __annotations__ returned all the time, or never returned. Otherwise some cases could modify __annotations__, and some couldn't.

I think you're right!  And since there are definitely circumstances in which it can't return __annotations__ directly, that indicates that it should never return __annotations__ directly.  Good call!

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43817>
_______________________________________


More information about the Python-bugs-list mailing list