Fix warning for __new__ of NamedTuple subclasses#606
Conversation
f9655b6 to
26d5492
Compare
gaborbernat
left a comment
There was a problem hiding this comment.
Please run and fix the pre-ocmmit checks.
| outer = getattr(outer, class_name, None) | ||
| if outer is None: |
| dedent( | ||
| """ | ||
| .. autofunction:: dummy_module.undocumented_function_with_defaults | ||
| """, |
There was a problem hiding this comment.
define the multiline docstring on its own, to decrease indentation and nesting
|
|
||
| for f in Path(app.srcdir).glob("*.rst"): | ||
| f.unlink() | ||
| (Path(app.srcdir) / "index.rst").write_text( |
There was a problem hiding this comment.
define the multiline docstring on its own, to decrease indentation and nesting
|
Addressed all three review comments:
|
|
|
||
| for rst_file in Path(app.srcdir).glob("*.rst"): | ||
| rst_file.unlink() | ||
| index_content = dedent( |
There was a problem hiding this comment.
can move dedent into the write_text call and have the index_content be only the variable to save a few more lines.
|
|
||
| for rst_file in Path(app.srcdir).glob("*.rst"): | ||
| rst_file.unlink() | ||
| index_content = dedent( |
There was a problem hiding this comment.
can move dedent into the write_text call and have the index_content be only the variable to save a few more lines.
|
Moved |
f2a239b to
a6b9d22
Compare
|
@Fridayai700 can you please check that pre-commit is passing before you mark it ready for review. |
|
Fixed both issues:
|
|
@Fridayai700 I asked for the format 😊 |
|
Fixed — both test functions now use the same |
When documenting __new__ of a NamedTuple subclass, inspect.getmodule() returns None because __new__.__module__ is set to the synthetic 'namedtuple_<Name>' module. The subsequent getattr(None, class_name) raised AttributeError, which Sphinx caught and reported as a warning. Guard against None from both inspect.getmodule() and getattr() in the qualname resolution loop. Fixes tox-dev#601
- Use walrus operator for getattr None check - Extract multiline RST content into variables before write_text - Rename single-letter loop var 'f' to 'rst_file' Co-Authored-By: Claude Opus 4.6 <[email protected]>
Add PLR0911 to noqa for process_signature (7 return statements). Extract RST content into index_content variable per review pattern. Co-Authored-By: Claude Opus 4.6 <[email protected]>
1efdf58 to
10d97f8
Compare
Fixes #601
When documenting
__new__of a NamedTuple subclass,inspect.getmodule()returnsNonebecause__new__.__module__is set to the syntheticnamedtuple_<Name>module (not importable). The subsequentgetattr(None, class_name)raisedAttributeError, which Sphinx caught and reported as a warning:The fix guards against
Nonefrom bothinspect.getmodule()andgetattr()in the qualname resolution loop. When the module can't be resolved,process_signaturereturnsNone(skip processing) rather than crashing.Includes regression test with a NamedTuple subclass.