annotationlib: Improve test coverage #141174
Description
Activity
- addedtype-featureA feature request or enhancementA feature request or enhancement
on Nov 6, 2025 Currently there is no coverage for the 'else' case in
_build_closure():
Lines 842 to 845 in 14c6222
if i < len(freevars): name = freevars[i] else: name = "__cell__" 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:
Lines 1503 to 1509 in 14c6222
if func.__closure__ is None: nonlocal_vars = {} else: nonlocal_vars = { var : cell.cell_contents for var, cell in zip(code.co_freevars, func.__closure__) } 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.
Reacted by dr-carlos- added a commit that references this issue
on Nov 10, 2025 - added a commit that references this issue
on Nov 10, 2025 - added a commit that references this issue
on Nov 10, 2025 11 remaining items
Probaly! Haven't looked at the tests recently, so will double-check over the next day.
Reacted by Stan Ulbrych- added 6 commits that reference this issue
on Aug 13, 2026 Triage: Can this be clsoed as completed?
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 toannotationlibas a whole, so I'll close this issue.Reacted by Stan Ulbrych
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.pyreports 75% coverage, but this is mostly the library is already imported somewhere incoverage.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
ForwardReftest coverage #141175annotationlib.call_annotate_function()test coverage #141176annotationlib._Stringifiertest coverage #141220annotationlib.get_annotations()test coverage #141286annotationlib.get_annotations()test coverage (GH-141286) #141353ForwardReftest coverage (GH-141175) #141354annotationlib.call_annotate_function()test coverage (GH-141176) #141355annotationlib._Stringifiertest coverage (GH-141220) #141358type_repr()ofTemplatewith invalid syntax inInterpolation#155661get_annotations()on wrapped cyclicalfunctools.partial#155663ForwardRef#155689ForwardRef(GH-155689) #155707ForwardRef(GH-155689) #155708get_annotations()on wrapped cyclicalfunctools.partial(GH-155663) #155709get_annotations()on wrapped cyclicalfunctools.partial(GH-155663) #155710type_repr()ofTemplatewith invalid syntax inInterpolation(GH-155661) #155711type_repr()ofTemplatewith invalid syntax inInterpolation(GH-155661) #155712