Skip to content

Fix AttributeError on unresolved nested self-append (+=)#353

Open
santhreal wants to merge 1 commit into
chimpler:masterfrom
santhreal:fix/nested-self-append-typed-error
Open

Fix AttributeError on unresolved nested self-append (+=)#353
santhreal wants to merge 1 commit into
chimpler:masterfrom
santhreal:fix/nested-self-append-typed-error

Conversation

@santhreal

Copy link
Copy Markdown

Fixes #103.

Parsing a += self-append on a nested key whose self-reference stays unresolved crashes with a raw AttributeError: 'bool' object has no attribute 'count' instead of the intended error message. The += desugaring builds the self-substitution and its ConfigValues with a boolean in the instring slot, where every other call site passes the source string; when the unresolved substitution is reported, lineno(loc, instring) calls bool.count() and raises.

Passing the real instring through both call sites makes it raise the intended ConfigSubstitutionException with a correct line and column. Working += on an existing key is unaffected.

Repro:

from pyhocon import ConfigFactory
ConfigFactory.parse_string('foo: {bar: []}\nfoo.bar += []')

The += desugaring built the self-substitution and its ConfigValues with a
boolean in the instring slot instead of the source string. When such a
substitution stayed unresolved, formatting the error via lineno()/col() did
bool.count() and raised AttributeError instead of the intended
ConfigSubstitutionException. Pass the real instring through so the typed
error is raised with a correct line and column.

Fixes chimpler#103
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Appending to a nested array causes an exception in pyparsing due to wrong type

1 participant