
On 12/01/21 10:16 am, Larry Hastings wrote:
This is addressed in PEP 563, when it rejected the idea of using "function local state when defining annotations":
This would be prohibitively expensive for highly annotated code as the frames would keep all their objects alive. That includes predominantly objects that won't ever be accessed again.
I'm not sure what that's supposed to mean. Firstly, functions that reference nonlocal names don't keep whole frames alive, only the particular objects they reference. Secondly, if an annotation references something at module level, that something will also be kept alive unless it is explicitly removed from the module -- which could also be done at a local level if you didn't want to keep those things around. So I don't really see any difference between global and local state when it comes to things being kept alive by annotations. -- Greg