From: Patrick Steinhardt Date: Thu, 23 May 2019 21:01:44 +0000 (+0200) Subject: docs: do not inherit str for Match X-Git-Tag: v0.13.72~57^2~2 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=983b842cadcaa36b9493359bce695ad790cdb58c;p=zziplib 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__`. --- 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):