Skip to content

numpydoc validate can crash checking GL08 with a locally-scoped class #717

Open

Description

@dpward

#622 fixed the GL08 check for nested classes, but it introduced a crash in validate() for classes that are defined inside a function, if the constructor does not have a docstring.

def factory():
    class LocalClass:
        def __init__(self, value):
            # no docstring
            self.value = value

    return LocalClass

MyClass = factory()

With the example above in factory.py:

$ python -m numpydoc validate factory.MyClass.__init__
Traceback (most recent call last):
  File "<frozen runpy>", line 203, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File ".../site-packages/numpydoc/__main__.py", line 7, in <module>
    raise SystemExit(main())
                     ~~~~^^
  File ".../site-packages/numpydoc/cli.py", line 138, in main
    return func(**args)
  File ".../site-packages/numpydoc/cli.py", line 25, in validate_object
    results = validate(import_path)
  File ".../site-packages/numpydoc/validate.py", line 675, in validate
    cls = Validator._load_obj(f"{doc.code_obj.__module__}.{cls_name}")
  File ".../site-packages/numpydoc/validate.py", line 268, in _load_obj
    obj = getattr(obj, part)
AttributeError: 'function' object has no attribute '<locals>'

Here, __qualname__ is factory.<locals>.LocalClass.__init__. The local namespace is not being handled.

Activity

  1. mattgebert commented on Nov 5, 2026

    @mattgebert
    Contributor

    Thanks for this - will take a look into handling this case shortly! Sorry it's cause a regression.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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