You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing test suite for annotationlib is good, but there is still a decent amount of line/branch coverage missing. coverage.py reports 75% coverage, but this is mostly the library is already imported somewhere in coverage.py, so all global statements are marked as 'missing'.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
But I'm not sure what conditions would cause __closure__ and __code__.co_freevars to be different lengths.
Git blame says that @JelleZijlstra wrote this code, is there a particular object you'd expect to behave this way?
The only other place in the stdlib where both are used together is inspect.getclosurevars(), which simply zips the closure and freevars together:
I think that could only happen with a manually constructed code object (or if there's a bug in the compiler). I wrote it that way to make the code robust to this case, but it might have been better to throw an error instead if the lengths mismatch.
It's completed, for now, until new features get added to annotationlib which aren't tested properly.
But at that point it should be related to the specific feature, not to annotationlib as a whole, so I'll close this issue.
Activity
dr-carlos commentedon Nov 9, 2025
Currently there is no coverage for the 'else' case in
_build_closure():cpython/Lib/annotationlib.py
Lines 842 to 845 in 14c6222
But I'm not sure what conditions would cause
__closure__and__code__.co_freevarsto be different lengths.Git blame says that @JelleZijlstra wrote this code, is there a particular object you'd expect to behave this way?
The only other place in the stdlib where both are used together is
inspect.getclosurevars(), which simply zips the closure and freevars together:cpython/Lib/inspect.py
Lines 1503 to 1509 in 14c6222
JelleZijlstra commentedon Nov 10, 2025
I think that could only happen with a manually constructed code object (or if there's a bug in the compiler). I wrote it that way to make the code robust to this case, but it might have been better to throw an error instead if the lengths mismatch.
gh-141174: Improve `annotationlib.get_annotations()` test coverage (#…
pythongh-141174: Improve `annotationlib.get_annotations()` test cover…
gh-141174: Improve `ForwardRef` test coverage (#141175)
pythongh-141174: Improve `ForwardRef` test coverage (pythonGH-141175)
pythongh-141174: Improve `ForwardRef` test coverage (pythonGH-141175)
gh-141174: Improve `annotationlib.call_annotate_function()` test cove…
pythongh-141174: Improve `annotationlib.call_annotate_function()` tes…
gh-141174: Improve `annotationlib._Stringifier` test coverage (#141220)
pythongh-141174: Improve `annotationlib._Stringifier` test coverage (p…
[3.14] gh-141174: Improve `annotationlib.get_annotations()` test cove…
11 remaining items
dr-carlos commentedon Aug 12, 2026
Probaly! Haven't looked at the tests recently, so will double-check over the next day.
gh-141174: Test re-stringifying a `ForwardRef` (#155689)
gh-141174: Test `get_annotations()` on wrapped cyclical `functools.pa…
gh-141174: Test `type_repr()` of `Template` with invalid syntax in `I…
[3.14] gh-141174: Test re-stringifying a `ForwardRef` (GH-155689) (#1…
[3.14] gh-141174: Test `type_repr()` of `Template` with invalid synta…
[3.14] gh-141174: Test `get_annotations()` on wrapped cyclical `funct…
dr-carlos commentedon Aug 13, 2026
It's completed, for now, until new features get added to
annotationlibwhich aren't tested properly.But at that point it should be related to the specific feature, not to
annotationlibas a whole, so I'll close this issue.pythongh-141174: Test re-stringifying a `ForwardRef` (python#155689)
pythongh-141174: Test `get_annotations()` on wrapped cyclical `functo…
pythongh-141174: Test `type_repr()` of `Template` with invalid syntax…
[3.15] gh-141174: Test re-stringifying a `ForwardRef` (GH-155689) (#1…
[3.15] gh-141174: Test `type_repr()` of `Template` with invalid synta…
[3.15] gh-141174: Test `get_annotations()` on wrapped cyclical `funct…