diff options
author | ptmcg <ptmcg@austin.rr.com> | 2019-07-05 10:26:16 -0500 |
---|---|---|
committer | ptmcg <ptmcg@austin.rr.com> | 2019-07-05 10:26:16 -0500 |
commit | c5c4ca6438ec0114c187beb6b8a2298b41eb9fe2 (patch) | |
tree | 2d82997573bf17079be77d9d5dbac7e6a5526a69 | |
parent | 0ca1706db7cccad4acf74ff8ab2287f600ed3f40 (diff) | |
download | pyparsing-git-c5c4ca6438ec0114c187beb6b8a2298b41eb9fe2.tar.gz |
Further mods to `Forward.__str__` to possibly address memory issues reported in #85 and #91, and also does not stomp on user-defined expression names
-rw-r--r-- | pyparsing.py | 15 | ||||
-rw-r--r-- | unitTests.py | 3 |
2 files changed, 11 insertions, 7 deletions
diff --git a/pyparsing.py b/pyparsing.py index 93efe48..febefc2 100644 --- a/pyparsing.py +++ b/pyparsing.py @@ -96,7 +96,7 @@ classes inherit from. Use the docstrings for examples of how to: """ __version__ = "2.4.1" -__versionTime__ = "05 Jul 2019 04:57 UTC" +__versionTime__ = "05 Jul 2019 15:20 UTC" __author__ = "Paul McGuire <ptmcg@users.sourceforge.net>" import string @@ -4793,19 +4793,22 @@ class Forward(ParseElementEnhance): def __str__( self ): if hasattr(self, "name"): return self.name + if self.strRepr is not None: + return self.strRepr - # Avoid infinite recursion by setting a temporary name - self.name = self.__class__.__name__ + ": ..." + # Avoid infinite recursion by setting a temporary strRepr + self.strRepr = ": ..." # Use the string representation of main expression. + retString = '...' try: if self.expr is not None: - retString = _ustr(self.expr) + retString = _ustr(self.expr)[:1000] else: retString = "None" finally: - self.name = self.__class__.__name__ + ": " + retString - return self.name + self.strRepr = self.__class__.__name__ + ": " + retString + return self.strRepr def copy(self): if self.expr is not None: diff --git a/unitTests.py b/unitTests.py index 52ad305..6411350 100644 --- a/unitTests.py +++ b/unitTests.py @@ -2981,7 +2981,7 @@ class SetNameTest(ParseTestCase): + | - term Forward: ?: term ?: term - Forward: {a | b | c [{d | e | f Forward: ...}]...} + Forward: {a | b | c [{d | e | f : ...}]...} int [, int]... (len) int... nested () expression @@ -2992,6 +2992,7 @@ class SetNameTest(ParseTestCase): for t,e in zip(tests, expected): tname = str(t) + print_(tname) self.assertEqual(tname, e, "expression name mismatch, expected {0} got {1}".format(e, tname)) class TrimArityExceptionMaskingTest(ParseTestCase): |