From 983b842cadcaa36b9493359bce695ad790cdb58c Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Thu, 23 May 2019 23:01:44 +0200 Subject: [PATCH] docs: do not inherit str for Match Instead of inheriting str, we can simply implement `__repr__` to return a string representation of the pattern itself. This fixes compatibility with Python 3, which throws when executing `str.__init__`. --- docs/zzipdoc/match.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/zzipdoc/match.py b/docs/zzipdoc/match.py index d1b2b0d..a8bbd1f 100644 --- a/docs/zzipdoc/match.py +++ b/docs/zzipdoc/match.py @@ -55,7 +55,7 @@ class MatchReplace: def __rlshift__(self, count): self.count = count ; return self -class Match(str): +class Match: """ A Match is actually a mix of a Python Pattern and MatchObject """ def __init__(self, pattern = None, flags = None): """ flags is a string: 'i' for case-insensitive etc.; it is just @@ -64,7 +64,6 @@ class Match(str): def __call__(self, pattern, flags = None): assert isinstance(pattern, str) or pattern is None assert isinstance(flags, str) or flags is None - str.__init__(self, pattern) self.replaced = 0 # set by subn() inside MatchReplace self.found = None # set by search() to a MatchObject self.pattern = pattern @@ -74,6 +73,8 @@ class Match(str): else: self.regex = re.compile(self.pattern) return self + def __repr__(self): + return self.pattern def __truth__(self): return self.found is not None def __and__(self, string): -- 2.40.0