GeezerVison is showing github.com — annotationlib: Improve test coverage · Issue #141174 · python/cpython
annotationlib: Improve test coverage #141174DescriptionFeature 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
Activitydr-carlos commented on Nov 9, 2025 ContributorAuthor More actions Currently there is no coverage for the 'else' case in _build_closure():
|
if i < len(freevars): |
|
name = freevars[i] |
|
else: |
|
name = "__cell__" |
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:
|
if func.__closure__ is None: |
|
nonlocal_vars = {} |
|
else: |
|
nonlocal_vars = { |
|
var : cell.cell_contents |
|
for var, cell in zip(code.co_freevars, func.__closure__) |
|
} |
JelleZijlstra commented on 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. added a commit that references this issue on Nov 10, 2025gh-141174: Improve `annotationlib.call_annotate_function()` test cove… dr-carlos commented on Aug 12, 2026 ContributorAuthor More actions Probaly! Haven't looked at the tests recently, so will double-check over the next day. added 6 commits that reference this issue on Aug 13, 2026gh-141174: Test `get_annotations()` on wrapped cyclical `functools.pa… gh-141174: Test `type_repr()` of `Template` with invalid syntax in `I… dr-carlos commented on Aug 13, 2026 ContributorAuthor More actions
Triage: Can this be clsoed as completed?
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.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|