Skip to content

pydoc emits deprecation warnings about package metadata #103624

Open
@dlax

Description

@dlax

Bug report

Some packages are moving away from defining metadata statically and instead recommend the use of importlib.metadata while deprecating direct access to package's attribute; this applies to __version__ in particular, but also to other ones such as __author__.

See for example jsonschema, changed in python-jsonschema/jsonschema@656a86a or attrs, changed in python-attrs/attrs@d4934b1#diff-4fc63db1f2fcb7c6e464ee9a77c3c74e90dd191d1c9ffc3bdd1234d3a6663dc0.

The deprecation warning appears upon pydoc invocations, e.g.:

$  pydoc jsonschema
/usr/lib/python3.11/pydoc.py:1289: DeprecationWarning: Accessing jsonschema.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for jsonschema's version.
  if hasattr(object, '__version__'):
/usr/lib/python3.11/pydoc.py:1290: DeprecationWarning: Accessing jsonschema.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for jsonschema's version.
  version = str(object.__version__)
$ pydoc attrs
/usr/lib/python3.11/pydoc.py:1289: DeprecationWarning: Accessing attrs.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
  if hasattr(object, '__version__'):
/usr/lib/python3.11/pydoc.py:1290: DeprecationWarning: Accessing attrs.__version__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
  version = str(object.__version__)
/usr/lib/python3.11/pydoc.py:1296: DeprecationWarning: Accessing attrs.__author__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
  if hasattr(object, '__author__'):
/usr/lib/python3.11/pydoc.py:1297: DeprecationWarning: Accessing attrs.__author__ is deprecated and will be removed in a future release. Use importlib.metadata directly to query for attrs's packaging metadata.
  result = result + self.section('AUTHOR', str(object.__author__))

Should we use importlib.metadata in Lib/pydoc.py, possibly with a fallback on the previous method?

Your environment

  • CPython versions tested on: 3.11.2, 3.12.0a7+d1e4917e06d5638f1a7fa189d6d63ec9c2a27753
  • Operating system and architecture: Debian bookworm, amd64

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions