Skip to content

Numpydoc 1.9.0: AttributeError: 'property' object has no attribute '__module__'. #638

Closed

Description

@jeremiedbb

Hi,

It looks like version 1.9.0 introduced a regression in the validation of property objects:
AttributeError: 'property' object has no attribute '__module__'.

It was detected in scikit-learn's CI; https://dev.azure.com/scikit-learn/scikit-learn/_build/results?buildId=77826&view=logs&jobId=dfe99b15-50db-5d7b-b1e9-4105c42527cf&j=dfe99b15-50db-5d7b-b1e9-4105c42527cf&t=ef785ae2-496b-5b02-9f0e-07a6c3ab3081

It can be reproduced by calling:
numpydoc.validate.validate("sklearn.model_selection._classification_threshold.FixedThresholdClassifier.classes_")

Activity

  1. Revathyvenugopal162 commented on Jul 1, 2025

    @Revathyvenugopal162

    We’re encountering a similar error in our libraries after upgrading to numpydoc 1.9.0 build: bump numpydoc from 1.8.0 to 1.9.0 ansys/ansys-sphinx-theme#735. The Sphinx build fails with the following message:

    Extension error (numpydoc.numpydoc):
    Handler <function mangle_docstrings at 0x7f13208353f0> for event 'autodoc-process-docstring' threw an exception (exception: 'NoneType' object has no attribute '__module__')
    

    This seems consistent with the regression described above.

  2. argerlt commented on Jul 3, 2025

    @argerlt

    AHA! I'm not going crazy! I had the same problem recently in another project, orix

    I created two different identical branches, and ran both through the ReadtheDocs automated builder, one with 18.0, the other with 19.0
    The first one succeeds: https://app.readthedocs.org/projects/orix/builds/28318535/

    The second one fails: https://app.readthedocs.org/projects/orix/builds/28726013/

    It looks like it fails when trying to parse the class propertyIpf_color_key_tsl.direction_color_key

    I think the change that caused the problem was this one

    I am not familiar enough with numpydoc to be sure, but is it sufficient to just add
    type(Rotation.angle) != property at line 640 of validate.py?

  3. thesamesam commented on Jul 19, 2025

    @thesamesam

    I think the change that caused the problem was #592

    cc @mattgebert

  4. mgorny commented on Jul 19, 2025

    @mgorny

    I think it's sufficient to reorder the conditions (at least for scikit-learn):

    diff --git a/numpydoc/validate.py b/numpydoc/validate.py
    index d0debfa..5fb90a9 100644
    --- a/numpydoc/validate.py
    +++ b/numpydoc/validate.py
    @@ -640,8 +640,8 @@ def validate(obj_name, validator_cls=None, **validator_kwargs):
             # Check if the object is a class and has a docstring in the constructor
             # Also check if code_obj is defined, as undefined for the AstValidator in validate_docstrings.py.
             if (
    -            doc.name.endswith(".__init__")
    -            and doc.is_function_or_method
    +            doc.is_function_or_method
    +            and doc.name.endswith(".__init__")
                 and hasattr(doc, "code_obj")
             ):
                 cls_name = doc.code_obj.__qualname__.split(".")[0]
  5. mattgebert commented on Jul 19, 2025

    @mattgebert
    Contributor

    Hey all, sorry for the shipped bug. Thanks for the tag. I've investigated it a bit further:

    >>> import numpydoc.validate
    >>> numpydoc.validate.validate("sklearn.model_selection._classification_threshold.FixedThresholdClassifier.classes_")
    
    Traceback (most recent call last):
      File "<python-input-8>", line 1, in <module>
        numpydoc.validate.validate("sklearn.model_selection._classification_threshold.FixedThresholdClassifier.classes_")
        ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      File "C:\Github\numpydoc\numpydoc\validate.py", line 650, in validate
        if doc.name.endswith(".__init__") and doc.is_function_or_method:
           ^^^^^^^^
      File "C:\Github\numpydoc\numpydoc\validate.py", line 234, in name
        return ".".join([self.obj.__module__, self.obj.__name__])
    

    The previous code for checking validation was

    if not doc.raw_doc:
            if "GL08" not in ignore_validation_comments:
                    errs.append(error("GL08"))
            return {
            ...
    

    This issue now arises because name is called on the Validator object inspecting property class, and the __module__ attribute doesn't exist on the property class. Conditionally checking doc.is_function_or_method first avoids the call to Validator.name and so the second part of the execution is avoided.

    A remaining issue that still remains is that GL08 is still reported for properties due to raw_doc (in the validate function) being None, while clean_doc actually has the property.getter docstring. Note, that clean_doc is sourced from pydoc.getdoc > pydoc._getdoc > pydoc._finddoc`. The implementation for GL08 considering properties is then probably incorrect but unrelated to the cause of this issue.

    >>> numpydoc.validate.validate("sklearn.model_selection._classification_threshold.FixedThresholdClassifier.classes_")
    {'type': 'property', 'docstring': 'Classes labels.', 'deprecated': False, 'file': 'C:\\Github\\venvs\\numpydoc\\Lib\\site-packages\\sklearn\\model_selection\\_classification_threshold.py', 'file_line': 320, 'errors': [('GL08', 'The object does not have a docstring')], 'examples_errors': ''}
    

    I actually would love to write a PR that properly supports property docstring annotations in numpydoc in the future. Looks like property testing seems largely avoided in the testing suit other than this class. This would also implement test cases that sufficiently test property class/decorator usage so this sort of bug doesn't happen again.

    In the meantime I've added the updated order switch for the conditional check to be

    if doc.is_function_or_method and doc.name.endswith(".__init__"):
    

    as suggested by @mgorny.

    I've added this to the PR #622 which also fixes additional bugs (including hook functionality for AST's) regarding the GL08 & constructor checking (just requires an approving review).

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