Skip to content

Exception using dataclasses with v1.9 #637

@EthanAtLL

Description

@EthanAtLL

Running uv run doctest.py on

# /// script
# dependencies = [
#   "numpydoc==1.8.0",
# ]
# ///
from dataclasses import dataclass
from numpydoc.validate import validate, get_doc_object

@dataclass
class MyClass:
    """Docs.
    """
    x: int

if __name__=='__main__':
    doc_obj = get_doc_object(MyClass)
    x = get_doc_object(MyClass.__init__)
    print(validate(x))

works yielding {'type': 'function', 'docstring': '', 'deprecated': False, 'file': '<string>', 'file_line': None, 'errors': [('GL08', 'The object does not have a docstring')], 'examples_errors': ''} but changing to numpydoc==1.90 gives

Traceback (most recent call last):
  File ".../doctest.py", line 18, in <module>
    print(validate(x))
  File ".../uv/environments-v2/doctest-76a1dd0b6c7db47d/lib/python3.9/site-packages/numpydoc/validate.py", line 648, in validate
    cls = Validator._load_obj(f"{doc.code_obj.__module__}.{cls_name}")
  File ".../uv/environments-v2/doctest-76a1dd0b6c7db47d/lib/python3.9/site-packages/numpydoc/validate.py", line 268, in _load_obj
    obj = getattr(obj, part)
AttributeError: module '__main__' has no attribute '__create_fn__'

The error only arises with the @dataclass annotation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions