Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Eclips4 opened this issue Apr 11, 2023 · 3 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@Eclips4
Copy link
Member

Eclips4 commented Apr 11, 2023

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

@Eclips4 Eclips4 added the type-bug An unexpected behavior, bug, or error label Apr 11, 2023
@sobolevn
Copy link
Member

sobolevn commented Apr 11, 2023

I can reproduce this issue without typing.TypedDict (which should not be used with @dataclass really):

>>> class Meta(type):
...    __call__ = dict
... 
>>> class Base(metaclass=Meta): ...
... 
>>> @dataclasses.dataclass
... class My(Base): ...
... 
# ValueError: no signature found for builtin type <class 'dict'>

@sobolevn sobolevn self-assigned this Apr 11, 2023
@sobolevn sobolevn added the stdlib Python modules in the Lib dir label Apr 11, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Apr 11, 2023
sobolevn added a commit to sobolevn/cpython that referenced this issue Apr 11, 2023
@sobolevn sobolevn changed the title Confusing traceback [dataclasses] Exception on __doc__ generation, when object signature cannot be fetched Apr 11, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Apr 17, 2023
@Eclips4
Copy link
Member Author

Eclips4 commented Apr 21, 2023

I think it's completed, so, I close it.

@Eclips4 Eclips4 closed this as completed Apr 21, 2023
@sobolevn sobolevn reopened this Apr 21, 2023
@sobolevn
Copy link
Member

It is not yet closed, because #103599 is not merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

3 participants