Fix GenericRepr dropping args of a secondary inspected class with no defaults - #13478
Open
uttam12331 wants to merge 1 commit into
Open
uttam12331 wants to merge 1 commit into
uttam12331 wants to merge 1 commit into
Conversation
In GenericRepr, the i == 0 branch guards the argument slice with `if default_len` (falling back to spec.args[1:] when a class has no default arguments), but the branch for subsequent inspected classes uses `spec.args[1:-default_len]` unconditionally. When such a class has no defaults, default_len is 0 and spec.args[1:-0] == spec.args[1:0] == [], so all of its arguments are silently dropped from the repr. Mirror the i == 0 guard so a secondary class with no defaults keeps its arguments, and add a regression test.
Member
|
Hi, change seems fine, even if maybe not too critical |
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.
Summary
In
GenericRepr(util/langhelpers.py), the loop overto_inspectguards the argument slice withif default_lenfor the first inspected class (i == 0), falling back tospec.args[1:]when a class has no default arguments. The branch for subsequent inspected classes does not:When a secondary inspected class has no default arguments,
default_len == 0, sospec.args[1:-default_len]becomesspec.args[1:-0]==spec.args[1:0]==[], and all of that class's arguments are silently dropped from the repr.Reproduction
Fix
Mirror the
i == 0guard:Tests
Added
GenericReprTest.test_multi_kw_secondary_no_defaults, which fails on the previous behavior (drops the secondary class's arg) and passes with the fix.