Skip to content

Avoid accessing __annotations__ in clean_dispatch_methods - #71

Open
Daverball wants to merge 2 commits into
morepath:masterfrom
seantis:fix/pep-649-compat
Open

Daverball wants to merge 2 commits into
morepath:masterfrom
seantis:fix/pep-649-compat

Conversation

@Daverball

Copy link
Copy Markdown
Contributor

With PEP-649/PEP-749 semantics this may invoke __annotate__ with the default format of Format.VALUE, which may raise exceptions, but also cause unnecessary work, if the annotations are never inspected.

I've noticed this when removing the from __future__ import annotations import from our code. For some reason with morepath 1.0 __annotations__ can show up in the dir of parent application classes, which in turn causes a crash in clean_dispatch_methods if not all the annotations are available at runtime.

While it may be a good idea to figure out why __annotations__ can end up in dir, it still seems a good idea to always skip accessing it, since even if it doesn't fail, it can still be expensive in Python 3.14+.

With PEP-649/PEP-749 semantics this may invoke `__annotate__` with the
default format of `Format.VALUE`, which may raise exceptions, but also
cause unnecessary work, if the annotations are never inspected.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant