Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
Bug report
Bug description:
Background:
Pydantic v1 modified builtin dataclass's__init__ method (wraps). When inspect on the modified dataclass, the class's signature will contain aself parameter.
Reproduce code with pydantic v1 installed:
fromdataclassesimportdataclassimportinspectfrompydanticimportBaseConfigfrompydantic.dataclassesimport_add_pydantic_validation_attributes@dataclassclassA:x:intprint(inspect.signature(A).parameters)# x_add_pydantic_validation_attributes(A,BaseConfig,False,"")print(inspect.signature(A).parameters)# self, xprint(A.__init__,hasattr(A.__init__,"__wrapped__"))# cyfunction A.__init__, Truemeth=inspect._descriptor_get(A.__init__,A)print(meth,hasattr(A.__init__,"__wrapped__"))# bound method A.__init__, Truemeth=inspect.unwrap(A.__init__,stop=lambdam:hasattr(m,"__signature__"))print(meth)# function A.__init__, this cause the signature error
This error is because of the unwrap and descriptor get behavior at
Lines 1924 to 1926 infe0e921
| meth=_descriptor_get(meth,cls) | |
| iffollow_wrapper_chains: | |
| meth=unwrap(meth,stop=lambdam:hasattr(m,"__signature__")) |
Thecyfunction __init__ descriptor return abound methoddataclass.__init__ and then unwrap it back to a functiondataclass.__init__.
Related to#132055
CPython versions tested on:
3.13
Operating systems tested on:
Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
Projects
Status
Done