Conversation
`_process_classdef` passed `cls_ctx=name.name`, but `Class.name` already returns the parso `Name` leaf, whose string lives on `.value`. Every class body therefore raised `AttributeError: 'Name' object has no attribute 'name'`, and since `bpc_utils` catches per node the process still exited 0 -- so the markers survived into the output and callers wrapping poseur in `subprocess.check_call` saw success. `_process_suite_node` declares `cls_ctx: Optional[str]`, stores it as `Optional[str]`, and hands it to `mangle()`, so `.value` is what was meant. Added `test_classdef`, which reproduces the crash without this change. `tests/sample.py` has no `class` at all, which is why the golden-file suite never caught it. Fixes #20
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #20.
The bug
_process_classdefpassescls_ctx=name.name:parso.python.tree.Class.namealready returns theNameleaf — as the comment on the line above says — and a parsoNamekeeps its string on.value. So every class body raisedAttributeError: 'Name' object has no attribute 'name'.Because
bpc_utils' walker catches exceptions per node, the process still exited 0. Positional-only markers therefore survived into the output while the caller was told the conversion had succeeded — which matters for thesubprocess.check_callintegration the README recommends.Plain module-level functions were unaffected, which is why this stayed hidden.
The fix
cls_ctx=name.value. That this is the intended value is clear from the surrounding contract:_process_suite_node(self, node, *, cls_ctx: Optional[str] = None)(poseur.py:442)self._cls_ctx # type: Optional[str](poseur.py:438)return self.mangle(self._cls_ctx, name)(poseur.py:1076)Test
test_classdefcovers the no-op case, the crash case, and the converted output. It fails onmaster:and passes with the fix, along with the rest of the suite:
tests/sample.pycontains noclassstatement at all, so the golden-file suite could never have caught this. The new test is written inline rather than by extendingsample.py/sample.txt, to keep the fixtures untouched.Real-world check
pcapkit/corekit/io.pyfrom PyPCAPKit has 12 positional-only parameters spread across class bodies. With this change,walrusthenposeurconvert it into something CPython 3.7 parses cleanly:Verified on CPython 3.7.16 with
parso0.6.2 andbpc-utils0.10.1.