diff options
author | ptmcg <ptmcg@austin.rr.com> | 2021-10-24 13:02:50 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2021-10-24 13:02:50 -0500 |
commit | 465c20f4b232979d07ad905596edcd8ed21b492e (patch) | |
tree | 2d3855ef3b35103e584ef16bdc41e6586e986758 | |
parent | 121a2394ec99f67a641a0d114c31f6f48482031f (diff) | |
download | pyparsing-git-465c20f4b232979d07ad905596edcd8ed21b492e.tar.gz |
Fixed bug where ParseResults accidentally created recursive contents. (Issue #315)pyparsing_3.0.1
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | pyparsing/__init__.py | 2 | ||||
-rw-r--r-- | pyparsing/results.py | 5 | ||||
-rw-r--r-- | tests/test_unit.py | 7 |
4 files changed, 16 insertions, 2 deletions
@@ -5,6 +5,10 @@ Change Log Version 3.0.1 - --------------- - Fixed bug where Word(max=n) did not match word groups less than length 'n'. + Thanks to Joachim Metz for catching this! + +- Fixed bug where ParseResults accidentally created recursive contents. + Joachim Metz on this one also! - Fixed bug where warn_on_multiple_string_args_to_oneof warning is raised even when not enabled. diff --git a/pyparsing/__init__.py b/pyparsing/__init__.py index cfbf5bc..6fbb7c9 100644 --- a/pyparsing/__init__.py +++ b/pyparsing/__init__.py @@ -105,7 +105,7 @@ __version__ = "{}.{}.{}".format(*__version_info__[:3]) + ( ), "", )[__version_info__.release_level == "final"] -__version_time__ = "24 October 2021 15:09 UTC" +__version_time__ = "24 October 2021 17:43 UTC" __versionTime__ = __version_time__ __author__ = "Paul McGuire <ptmcg.gm+pyparsing@gmail.com>" diff --git a/pyparsing/results.py b/pyparsing/results.py index a93abd8..194c3d9 100644 --- a/pyparsing/results.py +++ b/pyparsing/results.py @@ -183,7 +183,10 @@ class ParseResults: try: self[name] = toklist[0] except (KeyError, TypeError, IndexError): - self[name] = toklist + if toklist is not self: + self[name] = toklist + else: + self._name = name def __getitem__(self, i): if isinstance(i, (int, slice)): diff --git a/tests/test_unit.py b/tests/test_unit.py index b120835..fe4253d 100644 --- a/tests/test_unit.py +++ b/tests/test_unit.py @@ -2964,6 +2964,13 @@ class Test02_WithoutPackrat(ppt.TestParseResultsAsserts, TestCase): result, compare_list, msg="issue with ParseResults.insert()" ) + def testParseResultsAddingSuppressedTokenWithResultsName(self): + parser = "aaa" + (pp.NoMatch() | pp.Suppress("-"))("B") + try: + dd = parser.parse_string("aaa -").as_dict() + except RecursionError: + self.fail("fail getting named result when empty") + def testIgnoreString(self): """test ParserElement.ignore() passed a string arg""" |