Skip to content

Cannot import Anchor from importlib.resources #113238

Closed
@nsoranzo

Description

@nsoranzo

Bug report

Bug description:

The Python 3.12 documentation of the standard library module importlib.resources describes the importlib.resources.Anchor class, which is used for the type annotation of the files() function.
But in reality Anchor is not available to import from importlib.resources, it can only by found in importlib.resources._common as an alias for Package (which is instead available from importlib.resources).

To reproduce:

>>> from importlib.resources import Anchor
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'Anchor' from 'importlib.resources' (/usr/lib/python3.12/importlib/resources/__init__.py)

Expected result:
No ImportError

Use case:
To add type annotation to a function that receives an anchor and passes it to files().

CPython versions tested on:

3.12

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions