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

Unable to inspect class withcyfunction __init__ due to unwrap and descriptor behavior changed #137317

Closed
Labels
3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or error
@yanyongyu

Description

@yanyongyu

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

cpython/Lib/inspect.py

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

No one assigned

    Labels

    3.13bugs and security fixes3.14bugs and security fixes3.15new features, bugs and security fixesstdlibStandard Library Python modules in the Lib/ directorytopic-dataclassestype-bugAn unexpected behavior, bug, or error

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2026 Movatter.jp