You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Numpydoc 1.9.0: AttributeError: 'property' object has no attribute '__module__'. #638
It looks like version 1.9.0 introduced a regression in the validation of property objects: AttributeError: 'property' object has no attribute '__module__'.
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.
Reacted by Jorge Martinez, Maxime Rey, Austin Gerlt and Sébastien Morais
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]
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__"):
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).
Activity
Revathyvenugopal162 commentedon Jul 1, 2025
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:
This seems consistent with the regression described above.
argerlt commentedon Jul 3, 2025
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) != propertyat line 640 of validate.py?Disallow numpydoc 1.9.0
Disallow numpydoc 1.9.0
Disallow numpydoc 1.9.0
Disallow numpydoc 1.9.0
thesamesam commentedon Jul 19, 2025
cc @mattgebert
mgorny commentedon Jul 19, 2025
I think it's sufficient to reorder the conditions (at least for scikit-learn):
dev-python/numpydoc: Add a quick patch for upstream regression
fix(validate.py): switched conditional GL08 check order to avoid prop…
mattgebert commentedon Jul 19, 2025
Hey all, sorry for the shipped bug. Thanks for the tag. I've investigated it a bit further:
The previous code for checking validation was
This issue now arises because
nameis called on theValidatorobject inspectingpropertyclass, and the__module__attribute doesn't exist on thepropertyclass. Conditionally checkingdoc.is_function_or_methodfirst avoids the call toValidator.nameand 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 thevalidatefunction) being None, whileclean_docactually has theproperty.getterdocstring. Note, thatclean_docis sourced frompydoc.getdoc>pydoc._getdoc>pydoc._finddoc`. The implementation for GL08 considering properties is then probably incorrect but unrelated to the cause of this issue.I actually would love to write a PR that properly supports
propertydocstring annotations in numpydoc in the future. Looks likepropertytesting seems largely avoided in the testing suit other than this class. This would also implement test cases that sufficiently testpropertyclass/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
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).
Constructor checking for AST validator (#622)