Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Description
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:
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
- gh-128772: Fix - warnings.deprecated doesn't work well with pydoc #128781
- gh-128772: Fix pydoc for methods with __module__ is None #129177
- [3.13] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) #129653
- [3.12] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) #129654
- [3.13] gh-128772: Fix pydoc for methods with __module__ is None (GH-129177) #129655