diff options
author | Devin J. Pohly <djpohly@gmail.com> | 2022-07-09 07:01:08 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-09 07:01:08 -0500 |
commit | 7994f6f1cf3c05a9cd2d0e047caa782a8c0826f1 (patch) | |
tree | 5fde6681325f037e6dccaa91a0d388df0daeda0e | |
parent | 4432953173e8ba51ddcc4cf4ac9ead69c19d72d1 (diff) | |
download | pyparsing-git-7994f6f1cf3c05a9cd2d0e047caa782a8c0826f1.tar.gz |
Simpler fix for __new__ with copy.copy() (#427)
-rw-r--r-- | pyparsing/core.py | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/pyparsing/core.py b/pyparsing/core.py index 6b217a0..13ebf16 100644 --- a/pyparsing/core.py +++ b/pyparsing/core.py @@ -2348,6 +2348,10 @@ class Literal(Token): # Default behavior return super().__new__(cls) + # Needed to make copy.copy() work correctly if we customize __new__ + def __getnewargs__(self): + return (self.match,) + def __init__(self, match_string: str = "", *, matchString: str = ""): super().__init__() match_string = matchString or match_string @@ -2358,14 +2362,6 @@ class Literal(Token): self.mayReturnEmpty = False self.mayIndexError = False - def __copy__(self) -> "Literal": - # Needed to assist copy.copy() (used in ParserElement.copy), which - # doesn't handle the factory __new__ well. - obj = Literal(self.match) - # Copy instance attributes - obj.__dict__.update(self.__dict__) - return obj - def _generateDefaultName(self) -> str: return repr(self.match) |