Patchwork D2109: py3: make sure we return str from __repr__

login
register
mail settings
Submitter phabricator
Date Feb. 11, 2018, 12:39 p.m.
Message ID <differential-rev-PHID-DREV-nik66tv255pyhq4new5o-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27524/
State Superseded
Headers show

Comments

phabricator - Feb. 11, 2018, 12:39 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  1. skip-blame because we are just adding r'' prefixes

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/match.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 11, 2018, 2:06 p.m.
yuja requested changes to this revision.
yuja added inline comments.
This revision now requires changes to proceed.

INLINE COMMENTS

> match.py:456
>      def __repr__(self):
> -        return ('<exactmatcher files=%r>' % self._files)
> +        return (r'<exactmatcher files=%r>' % self._files)
>  

Maybe you know, `'%r' % [bytes, ...]` is incompatible across python versions,
so it's probably better to build a repr string in bytes, and convert it
to unicode.

See https://phab.mercurial-scm.org/rHGf0827211eb1fba515f4db9d32abaedf535e07375 and https://phab.mercurial-scm.org/rHGfc44c2657dc54b680583242916608c858026df19 for example.

REPOSITORY
  rHG Mercurial

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

To: pulkit, #hg-reviewers, durin42, yuja
Cc: yuja, mercurial-devel

Patch

diff --git a/mercurial/match.py b/mercurial/match.py
--- a/mercurial/match.py
+++ b/mercurial/match.py
@@ -345,7 +345,7 @@ 
         return 'all'
 
     def __repr__(self):
-        return '<alwaysmatcher>'
+        return r'<alwaysmatcher>'
 
 class nevermatcher(basematcher):
     '''Matches nothing.'''
@@ -368,7 +368,7 @@ 
         return False
 
     def __repr__(self):
-        return '<nevermatcher>'
+        return r'<nevermatcher>'
 
 class patternmatcher(basematcher):
 
@@ -398,7 +398,7 @@ 
         return self._prefix
 
     def __repr__(self):
-        return ('<patternmatcher patterns=%r>' % self._pats)
+        return (r'<patternmatcher patterns=%r>' % self._pats)
 
 class includematcher(basematcher):
 
@@ -425,7 +425,7 @@ 
                     for parentdir in util.finddirs(dir)))
 
     def __repr__(self):
-        return ('<includematcher includes=%r>' % self._pats)
+        return (r'<includematcher includes=%r>' % self._pats)
 
 class exactmatcher(basematcher):
     '''Matches the input files exactly. They are interpreted as paths, not
@@ -453,7 +453,7 @@ 
         return True
 
     def __repr__(self):
-        return ('<exactmatcher files=%r>' % self._files)
+        return (r'<exactmatcher files=%r>' % self._files)
 
 class differencematcher(basematcher):
     '''Composes two matchers by matching if the first matches and the second
@@ -493,7 +493,7 @@ 
         return self._m1.isexact()
 
     def __repr__(self):
-        return ('<differencematcher m1=%r, m2=%r>' % (self._m1, self._m2))
+        return (r'<differencematcher m1=%r, m2=%r>' % (self._m1, self._m2))
 
 def intersectmatchers(m1, m2):
     '''Composes two matchers by matching if both of them match.
@@ -559,7 +559,7 @@ 
         return self._m1.isexact() or self._m2.isexact()
 
     def __repr__(self):
-        return ('<intersectionmatcher m1=%r, m2=%r>' % (self._m1, self._m2))
+        return (r'<intersectionmatcher m1=%r, m2=%r>' % (self._m1, self._m2))
 
 class subdirmatcher(basematcher):
     """Adapt a matcher to work on a subdirectory only.
@@ -639,7 +639,7 @@ 
         return self._matcher.prefix() and not self._always
 
     def __repr__(self):
-        return ('<subdirmatcher path=%r, matcher=%r>' %
+        return (r'<subdirmatcher path=%r, matcher=%r>' %
                 (self._path, self._matcher))
 
 class unionmatcher(basematcher):
@@ -672,7 +672,7 @@ 
         return r
 
     def __repr__(self):
-        return ('<unionmatcher matchers=%r>' % self._matchers)
+        return (r'<unionmatcher matchers=%r>' % self._matchers)
 
 def patkind(pattern, default=None):
     '''If pattern is 'kind:pat' with a known kind, return kind.'''