Patchwork D3464: scmutil: clean up bytes/string cache decorator mess on Python 3 again

login
register
mail settings
Submitter phabricator
Date May 8, 2018, 4:26 a.m.
Message ID <differential-rev-PHID-DREV-nwu7f75ru5qjmoqp3b5o-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/31318/
State Superseded
Headers show

Comments

phabricator - May 8, 2018, 4:26 a.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  The previous fix to this area worked, but was dropping bytes in
  __dict__ on Python 3. This was causing subtle breakage in
  test-check-interfaces.py, and probably other things too.
  
  Fixed now.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/scmutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - May 8, 2018, 1:35 p.m.
Fixed the last AttributeError to raise the "s" name.

On Tue, 8 May 2018 04:26:35 +0000, durin42 (Augie Fackler) wrote:
>      def __delete__(self, obj):
>          try:
> -            del obj.__dict__[self.name]
> +            del obj.__dict__[self.sname]
>          except KeyError:
>              raise AttributeError(self.name)
phabricator - May 8, 2018, 1:35 p.m.
yuja added a comment.


  Fixed the last AttributeError to raise the "s" name.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1139,17 +1139,18 @@ 
 
     def __call__(self, func):
         self.func = func
-        self.name = func.__name__.encode('ascii')
+        self.sname = func.__name__
+        self.name = pycompat.sysbytes(self.sname)
         return self
 
     def __get__(self, obj, type=None):
         # if accessed on the class, return the descriptor itself.
         if obj is None:
             return self
         # do we need to check if the file changed?
-        if self.name in obj.__dict__:
+        if self.sname in obj.__dict__:
             assert self.name in obj._filecache, self.name
-            return obj.__dict__[self.name]
+            return obj.__dict__[self.sname]
 
         entry = obj._filecache.get(self.name)
 
@@ -1166,7 +1167,7 @@ 
 
             obj._filecache[self.name] = entry
 
-        obj.__dict__[self.name] = entry.obj
+        obj.__dict__[self.sname] = entry.obj
         return entry.obj
 
     def __set__(self, obj, value):
@@ -1180,11 +1181,11 @@ 
             ce = obj._filecache[self.name]
 
         ce.obj = value # update cached copy
-        obj.__dict__[self.name] = value # update copy returned by obj.x
+        obj.__dict__[self.sname] = value # update copy returned by obj.x
 
     def __delete__(self, obj):
         try:
-            del obj.__dict__[self.name]
+            del obj.__dict__[self.sname]
         except KeyError:
             raise AttributeError(self.name)