py3: abuse r'' to preserve str-ness of literals passed to __setattr__()
authorYuya Nishihara <yuya@tcha.org>
Sun, 26 Mar 2017 16:33:12 +0900
changeset 31644 f80d9ddc40f3
parent 31643 6ceb3c4c3ab6
child 31645 7095e783958d
py3: abuse r'' to preserve str-ness of literals passed to __setattr__()
mercurial/demandimport.py
mercurial/pure/osutil.py
mercurial/vfs.py
mercurial/windows.py
--- a/mercurial/demandimport.py	Sun Mar 26 17:12:06 2017 +0900
+++ b/mercurial/demandimport.py	Sun Mar 26 16:33:12 2017 +0900
@@ -76,9 +76,9 @@
         else:
             head = name
             after = []
-        object.__setattr__(self, "_data",
+        object.__setattr__(self, r"_data",
                            (head, globals, locals, after, level, set()))
-        object.__setattr__(self, "_module", None)
+        object.__setattr__(self, r"_module", None)
     def _extend(self, name):
         """add to the list of submodules to load"""
         self._data[3].append(name)
@@ -138,7 +138,7 @@
                 if modref and getattr(modref, head, None) == self:
                     setattr(modref, head, mod)
 
-            object.__setattr__(self, "_module", mod)
+            object.__setattr__(self, r"_module", mod)
 
     def __repr__(self):
         if self._module:
--- a/mercurial/pure/osutil.py	Sun Mar 26 17:12:06 2017 +0900
+++ b/mercurial/pure/osutil.py	Sun Mar 26 16:33:12 2017 +0900
@@ -342,8 +342,8 @@
             # unfortunately, f.name is '<fdopen>' at this point -- so we store
             # the name on this wrapper. We cannot just assign to f.name,
             # because that attribute is read-only.
-            object.__setattr__(self, 'name', name)
-            object.__setattr__(self, '_file', f)
+            object.__setattr__(self, r'name', name)
+            object.__setattr__(self, r'_file', f)
 
         def __iter__(self):
             return self._file
--- a/mercurial/vfs.py	Sun Mar 26 17:12:06 2017 +0900
+++ b/mercurial/vfs.py	Sun Mar 26 16:33:12 2017 +0900
@@ -480,7 +480,7 @@
     Do not instantiate outside of the vfs layer.
     """
     def __init__(self, fh):
-        object.__setattr__(self, '_origfh', fh)
+        object.__setattr__(self, r'_origfh', fh)
 
     def __getattr__(self, attr):
         return getattr(self._origfh, attr)
@@ -507,7 +507,7 @@
     """
     def __init__(self, fh, closer):
         super(delayclosedfile, self).__init__(fh)
-        object.__setattr__(self, '_closer', closer)
+        object.__setattr__(self, r'_closer', closer)
 
     def __exit__(self, exc_type, exc_value, exc_tb):
         self._closer.close(self._origfh)
@@ -618,7 +618,7 @@
     """
     def __init__(self, fh):
         super(checkambigatclosing, self).__init__(fh)
-        object.__setattr__(self, '_oldstat', util.filestat(fh.name))
+        object.__setattr__(self, r'_oldstat', util.filestat(fh.name))
 
     def _checkambig(self):
         oldstat = self._oldstat
--- a/mercurial/windows.py	Sun Mar 26 17:12:06 2017 +0900
+++ b/mercurial/windows.py	Sun Mar 26 16:33:12 2017 +0900
@@ -61,8 +61,8 @@
     OPWRITE = 2
 
     def __init__(self, fp):
-        object.__setattr__(self, '_fp', fp)
-        object.__setattr__(self, '_lastop', 0)
+        object.__setattr__(self, r'_fp', fp)
+        object.__setattr__(self, r'_lastop', 0)
 
     def __getattr__(self, name):
         return getattr(self._fp, name)
@@ -74,42 +74,42 @@
         self._fp.seek(0, os.SEEK_CUR)
 
     def seek(self, *args, **kwargs):
-        object.__setattr__(self, '_lastop', self.OPNONE)
+        object.__setattr__(self, r'_lastop', self.OPNONE)
         return self._fp.seek(*args, **kwargs)
 
     def write(self, d):
         if self._lastop == self.OPREAD:
             self._noopseek()
 
-        object.__setattr__(self, '_lastop', self.OPWRITE)
+        object.__setattr__(self, r'_lastop', self.OPWRITE)
         return self._fp.write(d)
 
     def writelines(self, *args, **kwargs):
         if self._lastop == self.OPREAD:
             self._noopeseek()
 
-        object.__setattr__(self, '_lastop', self.OPWRITE)
+        object.__setattr__(self, r'_lastop', self.OPWRITE)
         return self._fp.writelines(*args, **kwargs)
 
     def read(self, *args, **kwargs):
         if self._lastop == self.OPWRITE:
             self._noopseek()
 
-        object.__setattr__(self, '_lastop', self.OPREAD)
+        object.__setattr__(self, r'_lastop', self.OPREAD)
         return self._fp.read(*args, **kwargs)
 
     def readline(self, *args, **kwargs):
         if self._lastop == self.OPWRITE:
             self._noopseek()
 
-        object.__setattr__(self, '_lastop', self.OPREAD)
+        object.__setattr__(self, r'_lastop', self.OPREAD)
         return self._fp.readline(*args, **kwargs)
 
     def readlines(self, *args, **kwargs):
         if self._lastop == self.OPWRITE:
             self._noopseek()
 
-        object.__setattr__(self, '_lastop', self.OPREAD)
+        object.__setattr__(self, r'_lastop', self.OPREAD)
         return self._fp.readlines(*args, **kwargs)
 
 def posixfile(name, mode='r', buffering=-1):