Skip to content

[dataclasses] Exception on __doc__ generation, when object signature cannot be fetched #103449

Closed
@Eclips4

Description

@Eclips4

Reproducible on current main branch:

from dataclasses import dataclass
from typing import TypedDict



@dataclass
class Foo(TypedDict):
    bar: int

Traceback:

Traceback (most recent call last):
  File "/home/eclips4/projects/test.py", line 6, in <module>
    @dataclass
     ^^^^^^^^^
  File "/usr/local/lib/python3.12/dataclasses.py", line 1237, in dataclass
    return wrap(cls)
           ^^^^^^^^^
  File "/usr/local/lib/python3.12/dataclasses.py", line 1227, in wrap
    return _process_class(cls, init, repr, eq, order, unsafe_hash,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dataclasses.py", line 1113, in _process_class
    str(inspect.signature(cls)).replace(' -> None', ''))
        ^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/inspect.py", line 3252, in signature
    return Signature.from_callable(obj, follow_wrapped=follow_wrapped,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/inspect.py", line 2996, in from_callable
    return _signature_from_callable(obj, sigcls=cls,
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/inspect.py", line 2503, in _signature_from_callable
    sig = _get_signature_of(call)
          ^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/inspect.py", line 2556, in _signature_from_callable
    raise ValueError(
ValueError: no signature found for builtin type <class 'dict'>

However, this code works on 3.8 version (but of course we cannot instantiate a Test class)
Maybe we need to add a some check in sources of dataclass.
Also, this error is not critical, so, feel free to "close as not planned" =)

Linked PRs

Metadata

Metadata

Assignees

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