GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — annotationlib: Improve test coverage · Issue #141174 · python/cpython

annotationlib: Improve test coverage #141174

New issue
Copy link
New issue
Copy link
Closed
Closed
annotationlib: Improve test coverage#141174
Copy link
Labels
testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement

Description

@dr-carlos
dr-carlos
opened on Nov 6, 2025
Issue body actions

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 ForwardRef test coverage #141175
  • gh-141174: Improve annotationlib.call_annotate_function() test coverage #141176
  • gh-141174: Improve annotationlib._Stringifier test 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 ForwardRef test coverage (GH-141175) #141354
  • [3.14] gh-141174: Improve annotationlib.call_annotate_function() test coverage (GH-141176) #141355
  • [3.14] gh-141174: Improve annotationlib._Stringifier test coverage (GH-141220) #141358
  • gh-141174: Test type_repr() of Template with invalid syntax in Interpolation #155661
  • gh-141174: Test get_annotations() on wrapped cyclical functools.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 cyclical functools.partial (GH-155663) #155709
  • [3.14] gh-141174: Test get_annotations() on wrapped cyclical functools.partial (GH-155663) #155710
  • [3.15] gh-141174: Test type_repr() of Template with invalid syntax in Interpolation (GH-155661) #155711
  • [3.14] gh-141174: Test type_repr() of Template with invalid syntax in Interpolation (GH-155661) #155712

Activity

Next
  1. dr-carlos
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Nov 6, 2025
  2. StanFromIreland
    added
    testsTests in the Lib/test dirTests in the Lib/test dir
    on Nov 7, 2025
  3. picnixz
    added
    topic-typing
    on Nov 7, 2025
  4. dr-carlos commented on Nov 9, 2025

    @dr-carlos
    dr-carlos
    on Nov 9, 2025
    ContributorAuthor
    More actions

    Currently there is no coverage for the 'else' case in _build_closure():

    cpython/Lib/annotationlib.py

    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_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:

    cpython/Lib/inspect.py

    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__)
    }

  5. JelleZijlstra commented on Nov 10, 2025

    @JelleZijlstra
    JelleZijlstra
    on Nov 10, 2025
    Member
    More actions

    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
  6. JelleZijlstra
    added a commit that references this issue on Nov 10, 2025

    gh-141174: Improve `annotationlib.get_annotations()` test coverage (#…

    06b6228
  7. miss-islington
    added a commit that references this issue on Nov 10, 2025

    pythongh-141174: Improve `annotationlib.get_annotations()` test cover…

    520480e
  8. JelleZijlstra
    added a commit that references this issue on Nov 10, 2025

    gh-141174: Improve `ForwardRef` test coverage (#141175)

    19b5730
  9. miss-islington
    added 2 commits that reference this issue on Nov 10, 2025

    pythongh-141174: Improve `ForwardRef` test coverage (pythonGH-141175)

    58a689a

    pythongh-141174: Improve `ForwardRef` test coverage (pythonGH-141175)

    dc02f83
  10. JelleZijlstra
    added a commit that references this issue on Nov 10, 2025

    gh-141174: Improve `annotationlib.call_annotate_function()` test cove…

    1110e8f
  11. miss-islington
    added a commit that references this issue on Nov 10, 2025

    pythongh-141174: Improve `annotationlib.call_annotate_function()` tes…

    5b7e45e
  12. JelleZijlstra
    added a commit that references this issue on Nov 10, 2025

    gh-141174: Improve `annotationlib._Stringifier` test coverage (#141220)

    55ea132
  13. miss-islington
    added a commit that references this issue on Nov 10, 2025

    pythongh-141174: Improve `annotationlib._Stringifier` test coverage (p…

    f58915c
  14. JelleZijlstra
    added a commit that references this issue on Nov 10, 2025

    [3.14] gh-141174: Improve `annotationlib.get_annotations()` test cove…

    9221030
  15. 11 remaining items

  16. dr-carlos commented on Aug 12, 2026

    @dr-carlos
    dr-carlos
    on Aug 12, 2026
    ContributorAuthor
    More actions

    Probaly! Haven't looked at the tests recently, so will double-check over the next day.

    Reacted by Stan Ulbrych
  17. JelleZijlstra
    added 6 commits that reference this issue on Aug 13, 2026

    gh-141174: Test re-stringifying a `ForwardRef` (#155689)

    5dab490

    gh-141174: Test `get_annotations()` on wrapped cyclical `functools.pa…

    5d3f02a

    gh-141174: Test `type_repr()` of `Template` with invalid syntax in `I…

    5cc9e46

    [3.14] gh-141174: Test re-stringifying a `ForwardRef` (GH-155689) (#1…

    83197a5

    [3.14] gh-141174: Test `type_repr()` of `Template` with invalid synta…

    767e6ad

    [3.14] gh-141174: Test `get_annotations()` on wrapped cyclical `funct…

    5477222
  18. dr-carlos commented on Aug 13, 2026

    @dr-carlos
    dr-carlos
    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.

    Reacted by Stan Ulbrych
  19. dr-carlos
    closed this as completedon Aug 13, 2026
  20. mbeijen
    added 3 commits that reference this issue on Aug 14, 2026

    pythongh-141174: Test re-stringifying a `ForwardRef` (python#155689)

    af854b3

    pythongh-141174: Test `get_annotations()` on wrapped cyclical `functo…

    8dd40b9

    pythongh-141174: Test `type_repr()` of `Template` with invalid syntax…

    15a1acb
  21. hugovk
    added a commit that references this issue on Aug 19, 2026

    [3.15] gh-141174: Test re-stringifying a `ForwardRef` (GH-155689) (#1…

    be6e789
  22. hugovk
    added 2 commits that reference this issue on Aug 27, 2026

    [3.15] gh-141174: Test `type_repr()` of `Template` with invalid synta…

    4c9ac60

    [3.15] gh-141174: Test `get_annotations()` on wrapped cyclical `funct…

    94aa79c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    testsTests in the Lib/test dirTests in the Lib/test dirtopic-typingtype-featureA feature request or enhancementA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.