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: namespace can be non-`dict` · Issue #132426 · python/cpython

annotationlib: namespace can be non-dict #132426

New issue
Copy link
New issue
Copy link
Closed
Closed
annotationlib: namespace can be non-dict#132426
Copy link
Labels
3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

Description

@eliegoudout
eliegoudout
opened on Apr 12, 2025
Issue body actions

Hello!

I think the following, made so that get_annotate_function is usable in metaclasses' __new__, should check for Mapping since __prepare__ can provide any mapping (see picture from PEP3115.

cpython/Lib/annotationlib.py

Line 630 in a81232c

if isinstance(obj, dict):

Image

Linked PRs

  • gh-132426: get_annotate_function vs. mapping namespaces #132427
  • gh-132426: Add get_annotate_from_class_namespace replacing get_annotate_function #132490

Activity

  1. eliegoudout
    added a commit that references this issue on Apr 12, 2025

    fix: ns can be mapping (closes python#132426)

    This issue will close once commit 93afac8 is merged into the 'main' branch.
    93afac8
  2. eliegoudout commented on Apr 12, 2025

    @eliegoudout
    eliegoudout
    on Apr 12, 2025
    Author
    More actions

    However, I now realize that this is a major issue since there might be a conflict between the Mapping subtype's own annotations and the annotations it contains as a mapping for another type's namespace.

    Shouldn't we separate get_annotate_function into get_annotate_function and get_namespace_annotations? Or maybe add a keyword get_annotate_function(obj, *, is_namespace: bool)?

  3. picnixz
    added
    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
    stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directory
    topic-typing
    on Apr 12, 2025
  4. picnixz commented on Apr 12, 2025

    @picnixz
    picnixz
    on Apr 12, 2025
    Member
    More actions

    cc @JelleZijlstra

  5. picnixz
    added
    3.14bugs and security fixesbugs and security fixes
    on Apr 12, 2025
  6. JelleZijlstra
    pinned this issue on Apr 12, 2025
  7. JelleZijlstra
    unpinned this issue on Apr 12, 2025
  8. JelleZijlstra commented on Apr 13, 2025

    @JelleZijlstra
    JelleZijlstra
    on Apr 13, 2025
    Member
    More actions

    Good point! I think what I'd like to do is drop get_annotate_function completely (it's now equivalent to a simple getattr call and doesn't need to be a function) and add a new function get_annotate_from_class_namespace.

    Your proposed change is a bit dubious because "mapping" at the C level means something a little different (it basically just checks for the mp_subscr slot). Not sure if that will cause practical problems but better to be safe.

    However, I now realize that this is a major issue since there might be a conflict between the Mapping subtype's own annotations and the annotations it contains as a mapping for another type's namespace.

    Since instances no longer have accessible annotations by default, this will only be a problem in exotic cases like a Mapping that is also an instance of type. But again, better to be safe.

  9. JelleZijlstra
    added a commit that references this issue on Apr 14, 2025

    pythongh-132426: Add get_annotate_from_class_namespace replacing get_…

    c320bce
  10. JelleZijlstra
    added a commit that references this issue on May 4, 2025

    gh-132426: Add get_annotate_from_class_namespace replacing get_annota…

    7cb86c5
  11. JelleZijlstra commented on May 4, 2025

    @JelleZijlstra
    JelleZijlstra
    on May 4, 2025
    Member
    More actions

    Fixed by #132490, thanks for the report!

    Reacted by eliegoudout
  12. JelleZijlstra
    closed this as completedon May 4, 2025
  13. diegorusso
    added a commit that references this issue on May 4, 2025

    Merge remote-tracking branch 'origin/main' into call-len

    c03babc
  14. Pranjal095
    added a commit that references this issue on Jul 12, 2025

    pythongh-132426: Add get_annotate_from_class_namespace replacing get_…

    1b84635
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

    3.14bugs and security fixesbugs and security fixesstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-typingtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    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.