Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

warnings.deprecated doesn't work well withpydoc #128772

Closed
Labels
stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error
@Viicos

Description

@Viicos

Bug report

Bug description:

Steps to reproduce:

  • Create a module (testmodule.py):
    fromwarningsimportdeprecated@deprecated("Test")classA:pass
  • In the Python shell, run:
    importtestmodulehelp(testmodule)

This will raise aTypeError:

File"/fakepath/uv/python/cpython-3.13.1-linux-x86_64-gnu/lib/python3.13/pydoc.py",line245,inparentnamereturnobject.__module__+'.'+name~~~~~~~~~~~~~~~~~~^~~~~TypeError:unsupportedoperand type(s)for+:'NoneType'and'str'

warnings.deprecated is defining custom__new__ and__init_subclass__ methods:

cpython/Lib/warnings.py

Lines 588 to 615 in6e1e780

original_new=arg.__new__
@functools.wraps(original_new)
def__new__(cls,*args,**kwargs):
ifclsisarg:
warn(msg,category=category,stacklevel=stacklevel+1)
iforiginal_newisnotobject.__new__:
returnoriginal_new(cls,*args,**kwargs)
# Mirrors a similar check in object.__new__.
elifcls.__init__isobject.__init__and (argsorkwargs):
raiseTypeError(f"{cls.__name__}() takes no arguments")
else:
returnoriginal_new(cls)
arg.__new__=staticmethod(__new__)
original_init_subclass=arg.__init_subclass__
# We need slightly different behavior if __init_subclass__
# is a bound method (likely if it was implemented in Python)
ifisinstance(original_init_subclass,MethodType):
original_init_subclass=original_init_subclass.__func__
@functools.wraps(original_init_subclass)
def__init_subclass__(*args,**kwargs):
warn(msg,category=category,stacklevel=stacklevel+1)
returnoriginal_init_subclass(*args,**kwargs)
arg.__init_subclass__=classmethod(__init_subclass__)

and because these methods don't have a__module__ available (maybe they should?), we end up with the above exception.

Should we special case deprecated classes and other objects using thewarnings.deprecated decorator in pydoc to display specific information? I don't think it's relevant to show the__new__ and__init_subclass__ overridden methods in the documentation output.

CPython versions tested on:

3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp