`numpydoc validate` can crash checking GL08 with a locally-scoped class
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 68/100
Research direction
Start in numpydoc/validate.py at the validate() logic around line 675 that loads the class name from the constructor's qualname. Read the GL08 check and the existing coverage added for nested classes by issue #622, then reproduce the reported failure with the factory.py example. Done means validation handles the local class without raising AttributeError and a regression test covers this case.
Written by the indexing model from the issue text.
Description
#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.
- Dominant language
- Python
- Stars
- 354
- Forks
- 185
- Avg merge
- 4m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from numpy/numpydoc
-
Don't require ``RT01`` for propertiesMay be free again @Nani-2007-code claimed this 30 days ago, and no pull request is open. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
-
Difficulty 4/5 3-5 days Newbie friendliness 57/100
-
DOC: Version link overflowing on navbarMay be free again @swoyer2 claimed this 52 days ago, and no pull request is open. Open
Difficulty 3/5 1-2 days Newbie friendliness 52/100
-
needs-decision
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 3/5 1-2 days Newbie friendliness 63/100
Similar issues
-
00 - Bug component: numpy.linalg
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
521xueweihan/HelloGitHub#4543 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
emeryberger/CSrankings#15700 ·
Maintainers usually reply within 2 days
-
Bug | 工作不正常 Triage | 待检查
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
OneDragon-Anything/ZenlessZoneZero-OneDragon#3084 ·
Maintainers usually reply within 1 day
-
Task select patterns with uppercase letters never matchPossibly taken @manobhisriram claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day