Skip to content

Commit f5bdb2d

Browse files
committed
Issue #618 - fix reference to re_match attribute in copy of Word object to first check with hasattr
1 parent 8c61893 commit f5bdb2d

File tree

4 files changed

+20
-2
lines changed

4 files changed

+20
-2
lines changed

CHANGES

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ Required Python versions by pyparsing version
4444

4545
Version 3.2.5 - September, 2025
4646
-------------------------------
47+
- JINX! Well, 3.2.4 had a bug for `Word` expressions that include a space
48+
character, if that expression was then copied, either directly with .copy() or
49+
by adding a results name, or including in another construct (like `DelimitedList`)
50+
that makes a copy internally. Issue #618, reported by mstinberg, among others -
51+
thanks, and sorry for the inconvenience.
4752

4853

4954
Version 3.2.4 - September, 2025

pyparsing/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def __repr__(self):
125125

126126

127127
__version_info__ = version_info(3, 2, 5, "final", 1)
128-
__version_time__ = "16 Sep 2025 19:39 UTC"
128+
__version_time__ = "16 Sep 2025 22:24 UTC"
129129
__version__ = __version_info__.__version__
130130
__versionTime__ = __version_time__
131131
__author__ = "Paul McGuire <[email protected]>"

pyparsing/core.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3226,7 +3226,9 @@ def __init__(
32263226

32273227
def copy(self) -> Word:
32283228
ret: Word = cast(Word, super().copy())
3229-
ret.parseImpl = ret.parseImpl_regex # type: ignore[method-assign]
3229+
if hasattr(self, "re_match"):
3230+
ret.re_match = self.re_match
3231+
ret.parseImpl = ret.parseImpl_regex # type: ignore[method-assign]
32303232
return ret
32313233

32323234
def _generateDefaultName(self) -> str:

tests/test_unit.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7892,6 +7892,17 @@ def testWordParseImpl(self):
78927892
with self.assertRaisesParseException(expected_msg="Expected custom integer"):
78937893
custom_int.parse_string("z", parse_all=True)
78947894

7895+
def testWordCopyWhenWordCharsIncludeSpace(self):
7896+
word_with_space = pp.Word(pp.alphas + " ")
7897+
word_with_space.parse_string("ABC")
7898+
word_with_space.copy().parse_string("ABC")
7899+
7900+
def testWordCopyWhenWordCharsIncludeSpace2(self):
7901+
element = pp.QuotedString('"') | pp.Combine(pp.Word(' abcdefghijklmnopqrstuvwxyz'))
7902+
element.parse_string("abc")
7903+
element_list = pp.DelimitedList(element)
7904+
element_list.parse_string("abc")
7905+
78957906
def testLiteralVsKeyword(self):
78967907
integer = ppc.integer
78977908
literal_expr = integer + pp.Literal("start") + integer

0 commit comments

Comments
 (0)