#36978 closed Uncategorized (invalid)
Should django evaluate typing annotations at all?
| Reported by: | 93578237 | Owned by: | |
|---|---|---|---|
| Component: | Core (Other) | Version: | 5.2 |
| Severity: | Normal | Keywords: | typing, inspect, deferred annotations |
| Cc: | Triage Stage: | Unreviewed | |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
I previously opened a bug report #36903 related to deferred annotations in Python 3.14. I believe Django does not need to evaluate annotations using annotationlib.Format.FORWARDREF and could instead use annotationlib.Format.STRING.
Change History (2)
comment:1 by , 16 hours ago
| Component: | Uncategorized → Core (Other) |
|---|---|
| Resolution: | → invalid |
| Status: | new → closed |
comment:2 by , 14 hours ago
from inspect import *; from annotationlib import *; from typing import * if TYPE_CHECKING: x = int def foo(a: x) -> None: ... In [4]: %timeit signature(foo, annotation_format=Format.FORWARDREF) 25 μs ± 445 ns per loop (mean ± std. dev. of 7 runs, 10,000 loops each) In [5]: %timeit signature(foo, annotation_format=Format.STRING) 12.4 μs ± 495 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)
What am I missing?
Note:
See TracTickets
for help on using tickets.
Thanks, but I don't quite follow, doesn't
FORWARDREFleave the annotations unevaluated? I think I benched this at the time and found it was faster thanSTRING. It's also more friendly for any package extending Django's behavior, since it makes fewer assumptions.