diff --git a/contrib/check-code.py b/contrib/check-code.py --- a/contrib/check-code.py +++ b/contrib/check-code.py @@ -281,10 +281,10 @@ for tp in testpats[i]: p = tp[0] m = tp[1] - if p.startswith(r'^'): - p = r"^ [$>] (%s)" % p[1:] + if p.startswith('^'): + p = "^ [$>] (%s)" % p[1:] else: - p = r"^ [$>] .*(%s)" % p + p = "^ [$>] .*(%s)" % p utestpats[i].append((p, m) + tp[2:]) # don't transform the following rules: diff --git a/contrib/perf.py b/contrib/perf.py --- a/contrib/perf.py +++ b/contrib/perf.py @@ -1658,7 +1658,7 @@ ) else: os.environ[r'HGRCPATH'] = r' ' - os.system(r"%s version -q > NUL" % sys.argv[0]) + os.system("%s version -q > NUL" % sys.argv[0]) timer(d) fm.end() diff --git a/doc/gendoc.py b/doc/gendoc.py --- a/doc/gendoc.py +++ b/doc/gendoc.py @@ -22,7 +22,7 @@ # available. Relax C module requirements. os.environ[r'HGMODULEPOLICY'] = r'allow' # import from the live mercurial repo -sys.path.insert(0, r"..") +sys.path.insert(0, "..") from mercurial import demandimport demandimport.enable() diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py --- a/hgdemandimport/demandimportpy2.py +++ b/hgdemandimport/demandimportpy2.py @@ -70,9 +70,9 @@ head = name after = [] object.__setattr__( - self, r"_data", (head, globals, locals, after, level, set()) + self, "_data", (head, globals, locals, after, level, set()) ) - object.__setattr__(self, r"_module", None) + object.__setattr__(self, "_module", None) def _extend(self, name): """add to the list of submodules to load""" @@ -143,7 +143,7 @@ if modref and getattr(modref, head, None) is self: setattr(modref, head, mod) - object.__setattr__(self, r"_module", mod) + object.__setattr__(self, "_module", mod) def __repr__(self): if self._module: diff --git a/hgext/convert/common.py b/hgext/convert/common.py --- a/hgext/convert/common.py +++ b/hgext/convert/common.py @@ -493,7 +493,7 @@ # POSIX requires at least 4096 bytes for ARG_MAX argmax = 4096 try: - argmax = os.sysconf(r"SC_ARG_MAX") + argmax = os.sysconf("SC_ARG_MAX") except (AttributeError, ValueError): pass diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py --- a/hgext/convert/cvsps.py +++ b/hgext/convert/cvsps.py @@ -54,10 +54,8 @@ self.__dict__.update(entries) def __repr__(self): - items = ( - r"%s=%r" % (k, self.__dict__[k]) for k in sorted(self.__dict__) - ) - return r"%s(%s)" % (type(self).__name__, r", ".join(items)) + items = ("%s=%r" % (k, self.__dict__[k]) for k in sorted(self.__dict__)) + return "%s(%s)" % (type(self).__name__, ", ".join(items)) class logerror(Exception): diff --git a/hgext/githelp.py b/hgext/githelp.py --- a/hgext/githelp.py +++ b/hgext/githelp.py @@ -90,7 +90,7 @@ args = fancyopts.fancyopts(list(args), cmdoptions, opts, True) break except getopt.GetoptError as ex: - if r"requires argument" in ex.msg: + if "requires argument" in ex.msg: raise if (r'--' + ex.opt) in ex.msg: flag = b'--' + pycompat.bytestr(ex.opt) diff --git a/hgext/lfs/wireprotolfsserver.py b/hgext/lfs/wireprotolfsserver.py --- a/hgext/lfs/wireprotolfsserver.py +++ b/hgext/lfs/wireprotolfsserver.py @@ -249,7 +249,7 @@ if not exists: rsp[r'error'] = { r'code': 404, - r'message': r"The object does not exist", + r'message': "The object does not exist", } yield rsp continue @@ -257,7 +257,7 @@ elif not verifies: rsp[r'error'] = { r'code': 422, # XXX: is this the right code? - r'message': r"The object is corrupt", + r'message': "The object is corrupt", } yield rsp continue @@ -287,7 +287,7 @@ b'%s%s/.hg/lfs/objects/%s' % (req.baseurl, req.apppath, oid) ), # datetime.isoformat() doesn't include the 'Z' suffix - r"expires_at": expiresat.strftime(r'%Y-%m-%dT%H:%M:%SZ'), + "expires_at": expiresat.strftime(r'%Y-%m-%dT%H:%M:%SZ'), r'header': _buildheader(), } } diff --git a/hgext/narrow/narrowwirepeer.py b/hgext/narrow/narrowwirepeer.py --- a/hgext/narrow/narrowwirepeer.py +++ b/hgext/narrow/narrowwirepeer.py @@ -33,8 +33,8 @@ # TODO: don't blindly add include/exclude wireproto # arguments to unbundle. include, exclude = repo.narrowpats - kwargs[r"includepats"] = b','.join(include) - kwargs[r"excludepats"] = b','.join(exclude) + kwargs["includepats"] = b','.join(include) + kwargs["excludepats"] = b','.join(exclude) return orig(cmd, *args, **kwargs) extensions.wrapfunction(peer, b'_calltwowaystream', wrapped) diff --git a/hgext/record.py b/hgext/record.py --- a/hgext/record.py +++ b/hgext/record.py @@ -72,7 +72,7 @@ _(b'running non-interactively, use %s instead') % b'commit' ) - opts[r"interactive"] = True + opts["interactive"] = True overrides = {(b'experimental', b'crecord'): False} with ui.configoverride(overrides, b'record'): return commands.commit(ui, repo, *pats, **opts) diff --git a/hgext/remotefilelog/shallowutil.py b/hgext/remotefilelog/shallowutil.py --- a/hgext/remotefilelog/shallowutil.py +++ b/hgext/remotefilelog/shallowutil.py @@ -260,9 +260,9 @@ # v0, str(int(size)) is the header size = int(header) except ValueError: - raise RuntimeError(r"unexpected remotefilelog header: illegal format") + raise RuntimeError("unexpected remotefilelog header: illegal format") if size is None: - raise RuntimeError(r"unexpected remotefilelog header: no size found") + raise RuntimeError("unexpected remotefilelog header: no size found") return index + 1, size, flags diff --git a/hgext/zeroconf/__init__.py b/hgext/zeroconf/__init__.py --- a/hgext/zeroconf/__init__.py +++ b/hgext/zeroconf/__init__.py @@ -95,7 +95,7 @@ hostname = socket.gethostname().split(r'.')[0] host = hostname + r".local" - name = r"%s-%s" % (hostname, name) + name = "%s-%s" % (hostname, name) # advertise to browsers svc = Zeroconf.ServiceInfo( @@ -180,10 +180,10 @@ server.close() for value in l.found.values(): name = value.name[: value.name.index(b'.')] - url = r"http://%s:%s%s" % ( + url = "http://%s:%s%s" % ( socket.inet_ntoa(value.address), value.port, - value.properties.get(r"path", r"/"), + value.properties.get("path", "/"), ) yield b"zc-" + name, pycompat.bytestr(url) diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py --- a/mercurial/changegroup.py +++ b/mercurial/changegroup.py @@ -85,7 +85,7 @@ fh = open(filename, b"wb", 131072) else: fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") - fh = os.fdopen(fd, r"wb") + fh = os.fdopen(fd, "wb") cleanup = filename for c in chunks: fh.write(c) diff --git a/mercurial/context.py b/mercurial/context.py --- a/mercurial/context.py +++ b/mercurial/context.py @@ -71,7 +71,7 @@ __str__ = encoding.strmethod(__bytes__) def __repr__(self): - return r"<%s %s>" % (type(self).__name__, str(self)) + return "<%s %s>" % (type(self).__name__, str(self)) def __eq__(self, other): try: @@ -789,7 +789,7 @@ __str__ = encoding.strmethod(__bytes__) def __repr__(self): - return r"<%s %s>" % (type(self).__name__, str(self)) + return "<%s %s>" % (type(self).__name__, str(self)) def __hash__(self): try: diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -651,7 +651,7 @@ ) def debugdate(ui, date, range=None, **opts): """parse and display a date""" - if opts[r"extended"]: + if opts["extended"]: d = dateutil.parsedate(date, util.extendeddateformats) else: d = dateutil.parsedate(date) @@ -877,7 +877,7 @@ timestr = b'set ' else: timestr = time.strftime( - r"%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]) + "%Y-%m-%d %H:%M:%S ", time.localtime(ent[3]) ) timestr = encoding.strtolocal(timestr) if ent[1] & 0o20000: diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py --- a/mercurial/dirstate.py +++ b/mercurial/dirstate.py @@ -368,7 +368,7 @@ rereads the dirstate. Use localrepo.invalidatedirstate() if you want to check whether the dirstate has changed before rereading it.''' - for a in (r"_map", r"_branch", r"_ignore"): + for a in ("_map", "_branch", "_ignore"): if a in self.__dict__: delattr(self, a) self._lastnormaltime = 0 @@ -1399,9 +1399,9 @@ def addfile(self, f, oldstate, state, mode, size, mtime): """Add a tracked file to the dirstate.""" - if oldstate in b"?r" and r"_dirs" in self.__dict__: + if oldstate in b"?r" and "_dirs" in self.__dict__: self._dirs.addpath(f) - if oldstate == b"?" and r"_alldirs" in self.__dict__: + if oldstate == b"?" and "_alldirs" in self.__dict__: self._alldirs.addpath(f) self._map[f] = dirstatetuple(state, mode, size, mtime) if state != b'n' or mtime == -1: @@ -1417,11 +1417,11 @@ the file's previous state. In the future, we should refactor this to be more explicit about what that state is. """ - if oldstate not in b"?r" and r"_dirs" in self.__dict__: + if oldstate not in b"?r" and "_dirs" in self.__dict__: self._dirs.delpath(f) - if oldstate == b"?" and r"_alldirs" in self.__dict__: + if oldstate == b"?" and "_alldirs" in self.__dict__: self._alldirs.addpath(f) - if r"filefoldmap" in self.__dict__: + if "filefoldmap" in self.__dict__: normed = util.normcase(f) self.filefoldmap.pop(normed, None) self._map[f] = dirstatetuple(b'r', 0, size, 0) @@ -1434,11 +1434,11 @@ """ exists = self._map.pop(f, None) is not None if exists: - if oldstate != b"r" and r"_dirs" in self.__dict__: + if oldstate != b"r" and "_dirs" in self.__dict__: self._dirs.delpath(f) - if r"_alldirs" in self.__dict__: + if "_alldirs" in self.__dict__: self._alldirs.delpath(f) - if r"filefoldmap" in self.__dict__: + if "filefoldmap" in self.__dict__: normed = util.normcase(f) self.filefoldmap.pop(normed, None) self.nonnormalset.discard(f) diff --git a/mercurial/encoding.py b/mercurial/encoding.py --- a/mercurial/encoding.py +++ b/mercurial/encoding.py @@ -182,7 +182,7 @@ if encoding == b'UTF-8': # fast path return s - r = u.encode(_sysstr(encoding), r"replace") + r = u.encode(_sysstr(encoding), "replace") if u == r.decode(_sysstr(encoding)): # r is a safe, non-lossy encoding of s return safelocalstr(r) @@ -191,7 +191,7 @@ # we should only get here if we're looking at an ancient changeset try: u = s.decode(_sysstr(fallbackencoding)) - r = u.encode(_sysstr(encoding), r"replace") + r = u.encode(_sysstr(encoding), "replace") if u == r.decode(_sysstr(encoding)): # r is a safe, non-lossy encoding of s return safelocalstr(r) @@ -199,7 +199,7 @@ except UnicodeDecodeError: u = s.decode("utf-8", "replace") # last ditch # can't round-trip - return u.encode(_sysstr(encoding), r"replace") + return u.encode(_sysstr(encoding), "replace") except LookupError as k: raise error.Abort(k, hint=b"please check your locale settings") diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -591,9 +591,7 @@ break if currcls is object: - raise AttributeError( - r"type '%s' has no property '%s'" % (cls, propname) - ) + raise AttributeError("type '%s' has no property '%s'" % (cls, propname)) class wrappedfunction(object): diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py --- a/mercurial/filemerge.py +++ b/mercurial/filemerge.py @@ -934,10 +934,10 @@ name = os.path.join(tmproot, pre) if ext: name += ext - f = open(name, r"wb") + f = open(name, "wb") else: fd, name = pycompat.mkstemp(prefix=pre + b'.', suffix=ext) - f = os.fdopen(fd, r"wb") + f = os.fdopen(fd, "wb") return f, name def tempfromcontext(prefix, ctx): diff --git a/mercurial/hgweb/server.py b/mercurial/hgweb/server.py --- a/mercurial/hgweb/server.py +++ b/mercurial/hgweb/server.py @@ -62,7 +62,7 @@ def writelines(self, seq): for msg in seq: - self.handler.log_error(r"HG error: %s", encoding.strfromlocal(msg)) + self.handler.log_error("HG error: %s", encoding.strfromlocal(msg)) class _httprequesthandler(httpservermod.basehttprequesthandler): @@ -128,20 +128,20 @@ isinstance(e, (OSError, socket.error)) and e.errno == errno.ECONNRESET ): - tb = r"".join(traceback.format_exception(*sys.exc_info())) + tb = "".join(traceback.format_exception(*sys.exc_info())) # We need a native-string newline to poke in the log # message, because we won't get a newline when using an # r-string. This is the easy way out. newline = chr(10) self.log_error( r"Exception happened during processing " - r"request '%s':%s%s", + "request '%s':%s%s", self.path, newline, tb, ) - self._start_response(r"500 Internal Server Error", []) + self._start_response("500 Internal Server Error", []) self._write(b"Internal Server Error") self._done() @@ -335,8 +335,8 @@ def setup(self): self.connection = self.request - self.rfile = self.request.makefile(r"rb", self.rbufsize) - self.wfile = self.request.makefile(r"wb", self.wbufsize) + self.rfile = self.request.makefile("rb", self.rbufsize) + self.wfile = self.request.makefile("wb", self.wbufsize) try: diff --git a/mercurial/hgweb/wsgiheaders.py b/mercurial/hgweb/wsgiheaders.py --- a/mercurial/hgweb/wsgiheaders.py +++ b/mercurial/hgweb/wsgiheaders.py @@ -129,7 +129,7 @@ return self._headers[:] def __repr__(self): - return r"%s(%r)" % (self.__class__.__name__, self._headers) + return "%s(%r)" % (self.__class__.__name__, self._headers) def __str__(self): """str() returns the formatted headers, complete with end line, diff --git a/mercurial/hook.py b/mercurial/hook.py --- a/mercurial/hook.py +++ b/mercurial/hook.py @@ -38,7 +38,7 @@ if callable(funcname): obj = funcname - funcname = pycompat.sysbytes(obj.__module__ + r"." + obj.__name__) + funcname = pycompat.sysbytes(obj.__module__ + "." + obj.__name__) else: d = funcname.rfind(b'.') if d == -1: @@ -61,7 +61,7 @@ e1 = sys.exc_info() try: # extensions are loaded with hgext_ prefix - obj = __import__(r"hgext_%s" % pycompat.sysstr(modname)) + obj = __import__("hgext_%s" % pycompat.sysstr(modname)) except (ImportError, SyntaxError): e2 = sys.exc_info() if ui.tracebackflag: diff --git a/mercurial/httppeer.py b/mercurial/httppeer.py --- a/mercurial/httppeer.py +++ b/mercurial/httppeer.py @@ -543,7 +543,7 @@ try: # dump bundle to disk fd, filename = pycompat.mkstemp(prefix=b"hg-bundle-", suffix=b".hg") - with os.fdopen(fd, r"wb") as fh: + with os.fdopen(fd, "wb") as fh: d = fp.read(4096) while d: fh.write(d) diff --git a/mercurial/lock.py b/mercurial/lock.py --- a/mercurial/lock.py +++ b/mercurial/lock.py @@ -238,7 +238,7 @@ def __del__(self): if self.held: warnings.warn( - r"use lock.release instead of del lock", + "use lock.release instead of del lock", category=DeprecationWarning, stacklevel=2, ) diff --git a/mercurial/lsprof.py b/mercurial/lsprof.py --- a/mercurial/lsprof.py +++ b/mercurial/lsprof.py @@ -31,7 +31,7 @@ def __init__(self, data): self.data = data - def sort(self, crit=r"inlinetime"): + def sort(self, crit="inlinetime"): """XXX docstring""" # profiler_entries isn't defined when running under PyPy. if profiler_entry: diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -383,7 +383,7 @@ return self._ispatchinga(afile) and self._ispatchingb(bfile) def __repr__(self): - return r"" % (self.op, self.path) + return "" % (self.op, self.path) def readgitpatch(lr): diff --git a/mercurial/policy.py b/mercurial/policy.py --- a/mercurial/policy.py +++ b/mercurial/policy.py @@ -154,4 +154,4 @@ except AttributeError: if _isrustpermissive(): return default - raise ImportError(r"Cannot import name %s" % member) + raise ImportError("Cannot import name %s" % member) diff --git a/mercurial/pure/osutil.py b/mercurial/pure/osutil.py --- a/mercurial/pure/osutil.py +++ b/mercurial/pure/osutil.py @@ -257,7 +257,7 @@ creation = _OPEN_ALWAYS flags |= _O_APPEND else: - raise ValueError(r"invalid mode: %s" % pycompat.sysstr(mode)) + raise ValueError("invalid mode: %s" % pycompat.sysstr(mode)) fh = _kernel32.CreateFileA( name, diff --git a/mercurial/pycompat.py b/mercurial/pycompat.py --- a/mercurial/pycompat.py +++ b/mercurial/pycompat.py @@ -423,7 +423,7 @@ if isinstance(filename, str): return filename else: - raise TypeError(r"expect str, not %s" % type(filename).__name__) + raise TypeError("expect str, not %s" % type(filename).__name__) # In Python 2, fsdecode() has a very chance to receive bytes. So it's # better not to touch Python 2 part as it's already working fine. diff --git a/mercurial/statprof.py b/mercurial/statprof.py --- a/mercurial/statprof.py +++ b/mercurial/statprof.py @@ -126,20 +126,20 @@ __all__ = [b'start', b'stop', b'reset', b'display', b'profile'] skips = { - r"util.py:check", - r"extensions.py:closure", - r"color.py:colorcmd", - r"dispatch.py:checkargs", - r"dispatch.py:", - r"dispatch.py:_runcatch", - r"dispatch.py:_dispatch", - r"dispatch.py:_runcommand", - r"pager.py:pagecmd", - r"dispatch.py:run", - r"dispatch.py:dispatch", - r"dispatch.py:runcommand", - r"hg.py:", - r"evolve.py:warnobserrors", + "util.py:check", + "extensions.py:closure", + "color.py:colorcmd", + "dispatch.py:checkargs", + "dispatch.py:", + "dispatch.py:_runcatch", + "dispatch.py:_dispatch", + "dispatch.py:_runcommand", + "pager.py:pagecmd", + "dispatch.py:run", + "dispatch.py:dispatch", + "dispatch.py:runcommand", + "hg.py:", + "evolve.py:warnobserrors", } ########################################################################### @@ -1061,15 +1061,15 @@ displayargs[b'limit'] = 0.05 path = None for o, value in opts: - if o in (r"-l", r"--limit"): + if o in ("-l", "--limit"): displayargs[b'limit'] = float(value) - elif o in (r"-f", r"--file"): + elif o in ("-f", "--file"): path = value - elif o in (r"-o", r"--output-file"): + elif o in ("-o", "--output-file"): displayargs[b'outputfile'] = value - elif o in (r"-p", r"--script-path"): + elif o in ("-p", "--script-path"): displayargs[b'scriptpath'] = value - elif o in (r"-h", r"help"): + elif o in ("-h", "help"): printusage() return 0 else: @@ -1086,5 +1086,5 @@ return 0 -if __name__ == r"__main__": +if __name__ == "__main__": sys.exit(main()) diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py --- a/mercurial/utils/procutil.py +++ b/mercurial/utils/procutil.py @@ -263,7 +263,7 @@ return ( pycompat.safehasattr(sys, "frozen") or pycompat.safehasattr(sys, "importers") # new py2exe - or imp.is_frozen(r"__main__") # old py2exe + or imp.is_frozen("__main__") # old py2exe ) # tools/freeze diff --git a/mercurial/win32.py b/mercurial/win32.py --- a/mercurial/win32.py +++ b/mercurial/win32.py @@ -167,39 +167,39 @@ # These structs are only complete enough to achieve what we need. class CERT_CHAIN_CONTEXT(ctypes.Structure): _fields_ = ( - (r"cbSize", _DWORD), + ("cbSize", _DWORD), # CERT_TRUST_STATUS struct - (r"dwErrorStatus", _DWORD), - (r"dwInfoStatus", _DWORD), - (r"cChain", _DWORD), - (r"rgpChain", ctypes.c_void_p), - (r"cLowerQualityChainContext", _DWORD), - (r"rgpLowerQualityChainContext", ctypes.c_void_p), - (r"fHasRevocationFreshnessTime", _BOOL), - (r"dwRevocationFreshnessTime", _DWORD), + ("dwErrorStatus", _DWORD), + ("dwInfoStatus", _DWORD), + ("cChain", _DWORD), + ("rgpChain", ctypes.c_void_p), + ("cLowerQualityChainContext", _DWORD), + ("rgpLowerQualityChainContext", ctypes.c_void_p), + ("fHasRevocationFreshnessTime", _BOOL), + ("dwRevocationFreshnessTime", _DWORD), ) class CERT_USAGE_MATCH(ctypes.Structure): _fields_ = ( - (r"dwType", _DWORD), + ("dwType", _DWORD), # CERT_ENHKEY_USAGE struct - (r"cUsageIdentifier", _DWORD), - (r"rgpszUsageIdentifier", ctypes.c_void_p), # LPSTR * + ("cUsageIdentifier", _DWORD), + ("rgpszUsageIdentifier", ctypes.c_void_p), # LPSTR * ) class CERT_CHAIN_PARA(ctypes.Structure): _fields_ = ( - (r"cbSize", _DWORD), - (r"RequestedUsage", CERT_USAGE_MATCH), - (r"RequestedIssuancePolicy", CERT_USAGE_MATCH), - (r"dwUrlRetrievalTimeout", _DWORD), - (r"fCheckRevocationFreshnessTime", _BOOL), - (r"dwRevocationFreshnessTime", _DWORD), - (r"pftCacheResync", ctypes.c_void_p), # LPFILETIME - (r"pStrongSignPara", ctypes.c_void_p), # PCCERT_STRONG_SIGN_PARA - (r"dwStrongSignFlags", _DWORD), + ("cbSize", _DWORD), + ("RequestedUsage", CERT_USAGE_MATCH), + ("RequestedIssuancePolicy", CERT_USAGE_MATCH), + ("dwUrlRetrievalTimeout", _DWORD), + ("fCheckRevocationFreshnessTime", _BOOL), + ("dwRevocationFreshnessTime", _DWORD), + ("pftCacheResync", ctypes.c_void_p), # LPFILETIME + ("pStrongSignPara", ctypes.c_void_p), # PCCERT_STRONG_SIGN_PARA + ("dwStrongSignFlags", _DWORD), ) @@ -732,7 +732,7 @@ if e.errno != errno.EEXIST: raise else: - raise IOError(errno.EEXIST, r"No usable temporary filename found") + raise IOError(errno.EEXIST, "No usable temporary filename found") try: os.unlink(temp)