Patchwork D7606: fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3

login
register
mail settings
Submitter phabricator
Date Dec. 12, 2019, 12:52 p.m.
Message ID <39b0b2a6c1470bec78e93b21d96988c8@localhost.localdomain>
Download mbox | patch
Permalink /patch/43731/
State Not Applicable
Headers show

Comments

phabricator - Dec. 12, 2019, 12:52 p.m.
Closed by commit rHG229215fc1c1c: fuzz: fix mpatch_corpus to not have an overridden __repr__ on py3 (authored by spectral).
This revision was automatically updated to reflect the committed changes.

CHANGED PRIOR TO COMMIT
  https://phab.mercurial-scm.org/D7606?vs=18622&id=18627#toc

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D7606?vs=18622&id=18627

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7606/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D7606

AFFECTED FILES
  contrib/fuzz/mpatch_corpus.py

CHANGE DETAILS




To: spectral, #hg-reviewers, pulkit
Cc: mjpieters, mercurial-devel

Patch

diff --git a/contrib/fuzz/mpatch_corpus.py b/contrib/fuzz/mpatch_corpus.py
--- a/contrib/fuzz/mpatch_corpus.py
+++ b/contrib/fuzz/mpatch_corpus.py
@@ -2,6 +2,7 @@ 
 
 import argparse
 import struct
+import sys
 import zipfile
 
 from mercurial import (
@@ -14,16 +15,26 @@ 
 args = ap.parse_args()
 
 
-class deltafrag(object):
+if sys.version_info[0] < 3:
+
+    class py2reprhack(object):
+        def __repr__(self):
+            """Py2 calls __repr__ for `bytes(foo)`, forward to __bytes__"""
+            return self.__bytes__()
+
+
+else:
+
+    class py2reprhack(object):
+        """Not needed on py3."""
+
+
+class deltafrag(py2reprhack):
     def __init__(self, start, end, data):
         self.start = start
         self.end = end
         self.data = data
 
-    def __repr__(self):
-        # py2 calls __repr__ when you do `bytes(foo)`
-        return self.__bytes__()
-
     def __bytes__(self):
         return (
             struct.pack(">lll", self.start, self.end, len(self.data))
@@ -31,27 +42,19 @@ 
         )
 
 
-class delta(object):
+class delta(py2reprhack):
     def __init__(self, frags):
         self.frags = frags
 
-    def __repr__(self):
-        # py2 calls __repr__ when you do `bytes(foo)`
-        return self.__bytes__()
-
     def __bytes__(self):
         return b''.join(bytes(f) for f in self.frags)
 
 
-class corpus(object):
+class corpus(py2reprhack):
     def __init__(self, base, deltas):
         self.base = base
         self.deltas = deltas
 
-    def __repr__(self):
-        # py2 calls __repr__ when you do `bytes(foo)`
-        return self.__bytes__()
-
     def __bytes__(self):
         deltas = [bytes(d) for d in self.deltas]
         parts = (