]> granicus.if.org Git - zziplib/commitdiff
docs: do not inherit str for Match
authorPatrick Steinhardt <ps@pks.im>
Thu, 23 May 2019 21:01:44 +0000 (23:01 +0200)
committerPatrick Steinhardt <ps@pks.im>
Thu, 1 Aug 2019 08:14:04 +0000 (10:14 +0200)
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

index d1b2b0d710973ee9faf3dc6fd150a0cc9417ad0e..a8bbd1f5933d2b243409a8b93d246857e0f79fd6 100644 (file)
@@ -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):