Repository navigation
Closed
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
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
Links to previous discussion of this feature:
No response
Linked PRs
- gh-141174: Improve
ForwardReftest coverage #141175 - gh-141174: Improve
annotationlib.call_annotate_function()test coverage #141176 - gh-141174: Improve
annotationlib._Stringifiertest coverage #141220 - gh-141174: Improve
annotationlib.get_annotations()test coverage #141286 - [3.14] gh-141174: Improve
annotationlib.get_annotations()test coverage (GH-141286) #141353 - [3.14] gh-141174: Improve
ForwardReftest coverage (GH-141175) #141354 - [3.14] gh-141174: Improve
annotationlib.call_annotate_function()test coverage (GH-141176) #141355 - [3.14] gh-141174: Improve
annotationlib._Stringifiertest coverage (GH-141220) #141358 - gh-141174: Test
type_repr()ofTemplatewith invalid syntax inInterpolation#155661 - gh-141174: Test
get_annotations()on wrapped cyclicalfunctools.partial#155663 - gh-141174: Test re-stringifying a
ForwardRef#155689 - [3.15] gh-141174: Test re-stringifying a
ForwardRef(GH-155689) #155707 - [3.14] gh-141174: Test re-stringifying a
ForwardRef(GH-155689) #155708 - [3.15] gh-141174: Test
get_annotations()on wrapped cyclicalfunctools.partial(GH-155663) #155709 - [3.14] gh-141174: Test
get_annotations()on wrapped cyclicalfunctools.partial(GH-155663) #155710 - [3.15] gh-141174: Test
type_repr()ofTemplatewith invalid syntax inInterpolation(GH-155661) #155711 - [3.14] gh-141174: Test
type_repr()ofTemplatewith invalid syntax inInterpolation(GH-155661) #155712
Metadata
Metadata
Assignees
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement
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…