D7539: cleanup: fix docstring formatting

mharbison72 (Matt Harbison) phabricator at mercurial-scm.org
Mon Dec 2 00:13:08 UTC 2019


mharbison72 created this revision.
Herald added a reviewer: martinvonz.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is just removing the b'' prefix (except demandimportpy2), and making sure
  it is triple quoted.  I skipped the mapping.py module in zope because that's 3rd
  party code.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgdemandimport/demandimportpy2.py
  hgext/convert/cvsps.py
  hgext/convert/p4.py
  hgext/hgk.py
  hgext/rebase.py
  mercurial/changelog.py
  mercurial/color.py
  mercurial/context.py
  mercurial/crecord.py
  mercurial/dispatch.py
  mercurial/encoding.py
  mercurial/filemerge.py
  mercurial/hg.py
  mercurial/interfaces/dirstate.py
  mercurial/merge.py
  mercurial/parser.py
  mercurial/patch.py
  mercurial/subrepo.py
  mercurial/ui.py
  mercurial/utils/procutil.py
  mercurial/windows.py

CHANGE DETAILS

diff --git a/mercurial/windows.py b/mercurial/windows.py
--- a/mercurial/windows.py
+++ b/mercurial/windows.py
@@ -507,7 +507,7 @@
         pathexts = [b'']
 
     def findexisting(pathcommand):
-        b'Will append extension (if needed) and return existing file'
+        """Will append extension (if needed) and return existing file"""
         for ext in pathexts:
             executable = pathcommand + ext
             if os.path.exists(executable):
diff --git a/mercurial/utils/procutil.py b/mercurial/utils/procutil.py
--- a/mercurial/utils/procutil.py
+++ b/mercurial/utils/procutil.py
@@ -249,7 +249,8 @@
 
 
 def filter(s, cmd):
-    b"filter a string through a command that transforms its input to its output"
+    """filter a string through a command that transforms its input to its
+    output"""
     for name, fn in pycompat.iteritems(_filtertable):
         if cmd.startswith(name):
             return fn(s, cmd[len(name) :].lstrip())
@@ -347,7 +348,7 @@
     """return environ with optional override, useful for shelling out"""
 
     def py2shell(val):
-        b'convert python object into string that is useful to shell'
+        """convert python object into string that is useful to shell"""
         if val is None or val is False:
             return b'0'
         if val is True:
diff --git a/mercurial/ui.py b/mercurial/ui.py
--- a/mercurial/ui.py
+++ b/mercurial/ui.py
@@ -653,7 +653,8 @@
         return main, sub
 
     def configpath(self, section, name, default=_unset, untrusted=False):
-        b'get a path config item, expanded relative to repo root or config file'
+        """get a path config item, expanded relative to repo root or config
+        file"""
         v = self.config(section, name, default, untrusted)
         if v is None:
             return None
diff --git a/mercurial/subrepo.py b/mercurial/subrepo.py
--- a/mercurial/subrepo.py
+++ b/mercurial/subrepo.py
@@ -1528,7 +1528,7 @@
         return branch2rev, rev2branch
 
     def _gittracking(self, branches):
-        b'return map of remote branch to local tracking branch'
+        """return map of remote branch to local tracking branch"""
         # assumes no more than one local tracking branch for each remote
         tracking = {}
         for b in branches:
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -1570,7 +1570,7 @@
 
 
 class binhunk(object):
-    b'A binary patch file.'
+    """A binary patch file."""
 
     def __init__(self, lr, fname):
         self.text = None
diff --git a/mercurial/parser.py b/mercurial/parser.py
--- a/mercurial/parser.py
+++ b/mercurial/parser.py
@@ -34,17 +34,17 @@
         self.current = None
 
     def _advance(self):
-        b'advance the tokenizer'
+        """advance the tokenizer"""
         t = self.current
         self.current = next(self._iter, None)
         return t
 
     def _hasnewterm(self):
-        b'True if next token may start new term'
+        """True if next token may start new term"""
         return any(self._elements[self.current[0]][1:3])
 
     def _match(self, m):
-        b'make sure the tokenizer matches an end condition'
+        """make sure the tokenizer matches an end condition"""
         if self.current[0] != m:
             raise error.ParseError(
                 _(b"unexpected token: %s") % self.current[0], self.current[2]
@@ -52,7 +52,8 @@
         self._advance()
 
     def _parseoperand(self, bind, m=None):
-        b'gather right-hand-side operand until an end condition or binding met'
+        """gather right-hand-side operand until an end condition or binding
+        met"""
         if m and self.current[0] == m:
             expr = None
         else:
@@ -85,7 +86,7 @@
         return expr
 
     def parse(self, tokeniter):
-        b'generate a parse tree from tokens'
+        """generate a parse tree from tokens"""
         self._iter = tokeniter
         self._advance()
         res = self._parse()
@@ -93,13 +94,13 @@
         return res, pos
 
     def eval(self, tree):
-        b'recursively evaluate a parse tree using node methods'
+        """recursively evaluate a parse tree using node methods"""
         if not isinstance(tree, tuple):
             return tree
         return self._methods[tree[0]](*[self.eval(t) for t in tree[1:]])
 
     def __call__(self, tokeniter):
-        b'parse tokens into a parse tree and evaluate if methods given'
+        """parse tokens into a parse tree and evaluate if methods given"""
         t = self.parse(tokeniter)
         if self._methods:
             return self.eval(t)
diff --git a/mercurial/merge.py b/mercurial/merge.py
--- a/mercurial/merge.py
+++ b/mercurial/merge.py
@@ -2093,7 +2093,7 @@
 
 
 def recordupdates(repo, actions, branchmerge, getfiledata):
-    b"record merge actions to the dirstate"
+    """record merge actions to the dirstate"""
     # remove (must come first)
     for f, args, msg in actions.get(ACTION_REMOVE, []):
         if branchmerge:
diff --git a/mercurial/interfaces/dirstate.py b/mercurial/interfaces/dirstate.py
--- a/mercurial/interfaces/dirstate.py
+++ b/mercurial/interfaces/dirstate.py
@@ -24,7 +24,7 @@
         """Return a list of files containing patterns to ignore."""
 
     def _ignorefileandline(f):
-        b"Given a file `f`, return the ignore file and line that ignores it."
+        """Given a file `f`, return the ignore file and line that ignores it."""
 
     _checklink = interfaceutil.Attribute("""Callable for checking symlinks.""")
     _checkexec = interfaceutil.Attribute("""Callable for checking exec bits.""")
diff --git a/mercurial/hg.py b/mercurial/hg.py
--- a/mercurial/hg.py
+++ b/mercurial/hg.py
@@ -1345,7 +1345,7 @@
 
 
 def remoteui(src, opts):
-    b'build a remote ui from ui or repo and opts'
+    """build a remote ui from ui or repo and opts"""
     if util.safehasattr(src, b'baseui'):  # looks like a repository
         dst = src.baseui.copy()  # drop repo-specific config
         src = src.ui  # copy target options from repo
diff --git a/mercurial/filemerge.py b/mercurial/filemerge.py
--- a/mercurial/filemerge.py
+++ b/mercurial/filemerge.py
@@ -279,7 +279,7 @@
 
 
 def _eoltype(data):
-    b"Guess the EOL type of a file"
+    """Guess the EOL type of a file"""
     if b'\0' in data:  # binary
         return None
     if b'\r\n' in data:  # Windows
@@ -292,7 +292,7 @@
 
 
 def _matcheol(file, back):
-    b"Convert EOL markers in a file to match origfile"
+    """Convert EOL markers in a file to match origfile"""
     tostyle = _eoltype(back.data())  # No repo.wread filters?
     if tostyle:
         data = util.readfile(file)
diff --git a/mercurial/encoding.py b/mercurial/encoding.py
--- a/mercurial/encoding.py
+++ b/mercurial/encoding.py
@@ -312,13 +312,13 @@
 
 def colwidth(s):
     # type: (bytes) -> int
-    b"Find the column width of a string for display in the local encoding"
+    """Find the column width of a string for display in the local encoding"""
     return ucolwidth(s.decode(_sysstr(encoding), 'replace'))
 
 
 def ucolwidth(d):
     # type: (Text) -> int
-    b"Find the column width of a Unicode string for display"
+    """Find the column width of a Unicode string for display"""
     eaw = getattr(unicodedata, 'east_asian_width', None)
     if eaw is not None:
         return sum([eaw(c) in _wide and 2 or 1 for c in d])
@@ -436,7 +436,7 @@
 
 def lower(s):
     # type: (bytes) -> bytes
-    b"best-effort encoding-aware case-folding of local string s"
+    """best-effort encoding-aware case-folding of local string s"""
     try:
         return asciilower(s)
     except UnicodeDecodeError:
@@ -459,7 +459,7 @@
 
 def upper(s):
     # type: (bytes) -> bytes
-    b"best-effort encoding-aware case-folding of local string s"
+    """best-effort encoding-aware case-folding of local string s"""
     try:
         return asciiupper(s)
     except UnicodeDecodeError:
diff --git a/mercurial/dispatch.py b/mercurial/dispatch.py
--- a/mercurial/dispatch.py
+++ b/mercurial/dispatch.py
@@ -102,7 +102,7 @@
 
 
 def run():
-    b"run the command in sys.argv"
+    """run the command in sys.argv"""
     initstdio()
     with tracing.log('parse args into request'):
         req = request(pycompat.sysargv[1:])
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -102,7 +102,7 @@
         raise NotImplementedError(b"method must be implemented by subclass")
 
     def allchildren(self):
-        b"Return a list of all of the direct children of this node"
+        """Return a list of all of the direct children of this node"""
         raise NotImplementedError(b"method must be implemented by subclass")
 
     def nextsibling(self):
@@ -264,21 +264,23 @@
         return None
 
     def firstchild(self):
-        b"return the first child of this item, if one exists.  otherwise None."
+        """return the first child of this item, if one exists.  otherwise
+        None."""
         if len(self.hunks) > 0:
             return self.hunks[0]
         else:
             return None
 
     def lastchild(self):
-        b"return the last child of this item, if one exists.  otherwise None."
+        """return the last child of this item, if one exists.  otherwise
+        None."""
         if len(self.hunks) > 0:
             return self.hunks[-1]
         else:
             return None
 
     def allchildren(self):
-        b"return a list of all of the direct children of this node"
+        """return a list of all of the direct children of this node"""
         return self.hunks
 
     def __getattr__(self, name):
@@ -286,7 +288,7 @@
 
 
 class uihunkline(patchnode):
-    b"represents a changed line in a hunk"
+    """represents a changed line in a hunk"""
 
     def __init__(self, linetext, hunk):
         self.linetext = linetext
@@ -319,16 +321,18 @@
             return None
 
     def parentitem(self):
-        b"return the parent to the current item"
+        """return the parent to the current item"""
         return self.hunk
 
     def firstchild(self):
-        b"return the first child of this item, if one exists.  otherwise None."
+        """return the first child of this item, if one exists.  otherwise
+        None."""
         # hunk-lines don't have children
         return None
 
     def lastchild(self):
-        b"return the last child of this item, if one exists.  otherwise None."
+        """return the last child of this item, if one exists.  otherwise
+        None."""
         # hunk-lines don't have children
         return None
 
@@ -372,25 +376,27 @@
             return None
 
     def parentitem(self):
-        b"return the parent to the current item"
+        """return the parent to the current item"""
         return self.header
 
     def firstchild(self):
-        b"return the first child of this item, if one exists.  otherwise None."
+        """return the first child of this item, if one exists.  otherwise
+        None."""
         if len(self.changedlines) > 0:
             return self.changedlines[0]
         else:
             return None
 
     def lastchild(self):
-        b"return the last child of this item, if one exists.  otherwise None."
+        """return the last child of this item, if one exists.  otherwise
+        None."""
         if len(self.changedlines) > 0:
             return self.changedlines[-1]
         else:
             return None
 
     def allchildren(self):
-        b"return a list of all of the direct children of this node"
+        """return a list of all of the direct children of this node"""
         return self.changedlines
 
     def countchanges(self):
@@ -853,7 +859,7 @@
         self.currentselecteditem = currentitem
 
     def updatescroll(self):
-        b"scroll the screen to fully show the currently-selected"
+        """scroll the screen to fully show the currently-selected"""
         selstart = self.selecteditemstartline
         selend = self.selecteditemendline
 
@@ -871,7 +877,7 @@
             self.scrolllines(selstart - padstartbuffered)
 
     def scrolllines(self, numlines):
-        b"scroll the screen up (down) by numlines when numlines >0 (<0)."
+        """scroll the screen up (down) by numlines when numlines >0 (<0)."""
         self.firstlineofpadtoprint += numlines
         if self.firstlineofpadtoprint < 0:
             self.firstlineofpadtoprint = 0
@@ -973,7 +979,7 @@
                 )
 
     def toggleall(self):
-        b"toggle the applied flag of all items."
+        """toggle the applied flag of all items."""
         if self.waslasttoggleallapplied:  # then unapply them this time
             for item in self.headerlist:
                 if item.applied:
@@ -985,7 +991,8 @@
         self.waslasttoggleallapplied = not self.waslasttoggleallapplied
 
     def toggleallbetween(self):
-        b"toggle applied on or off for all items in range [lastapplied,current]."
+        """toggle applied on or off for all items in range [lastapplied,
+        current]. """
         if (
             not self.lastapplieditem
             or self.currentselecteditem == self.lastapplieditem
@@ -1026,7 +1033,8 @@
             nextitem = nextitem.nextitem()
 
     def togglefolded(self, item=None, foldparent=False):
-        b"toggle folded flag of specified item (defaults to currently selected)"
+        """toggle folded flag of specified item (defaults to currently
+        selected)"""
         if item is None:
             item = self.currentselecteditem
         if foldparent or (isinstance(item, uiheader) and item.neverunfolded):
@@ -1320,7 +1328,7 @@
     def printhunklinesbefore(
         self, hunk, selected=False, towin=True, ignorefolding=False
     ):
-        b"includes start/end line indicator"
+        """includes start/end line indicator"""
         outstr = b""
         # where hunk is in list of siblings
         hunkindex = hunk.header.hunks.index(hunk)
@@ -1529,7 +1537,7 @@
         return numlines
 
     def sigwinchhandler(self, n, frame):
-        b"handle window resizing"
+        """handle window resizing"""
         try:
             curses.endwin()
             self.xscreensize, self.yscreensize = scmutil.termsize(self.ui)
@@ -1599,11 +1607,11 @@
         return colorpair
 
     def initcolorpair(self, *args, **kwargs):
-        b"same as getcolorpair."
+        """same as getcolorpair."""
         self.getcolorpair(*args, **kwargs)
 
     def helpwindow(self):
-        b"print a help window to the screen.  exit after any keypress."
+        """print a help window to the screen.  exit after any keypress."""
         helptext = _(
             """            [press any key to return to the patch-display]
 
@@ -1654,7 +1662,7 @@
             pass
 
     def commitMessageWindow(self):
-        b"Create a temporary commit message editing window on the screen."
+        """Create a temporary commit message editing window on the screen."""
 
         curses.raw()
         curses.def_prog_mode()
@@ -1704,7 +1712,8 @@
         self.recenterdisplayedarea()
 
     def confirmationwindow(self, windowtext):
-        b"display an informational window, then wait for and return a keypress."
+        """display an informational window, then wait for and return a
+        keypress."""
 
         confirmwin = curses.newwin(self.yscreensize, 0, 0, 0)
         try:
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -1587,7 +1587,7 @@
         )
 
     def dirty(self, missing=False, merge=True, branch=True):
-        b"check whether a working directory is modified"
+        """check whether a working directory is modified"""
         # check subrepos first
         for s in sorted(self.substate):
             if self.sub(s).dirty(missing=missing):
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -330,7 +330,7 @@
 
 
 def valideffect(ui, effect):
-    b'Determine if the effect is valid or not.'
+    """Determine if the effect is valid or not."""
     return (not ui._terminfoparams and effect in _activeeffects(ui)) or (
         effect in ui._terminfoparams or effect[:-11] in ui._terminfoparams
     )
@@ -377,7 +377,7 @@
 
 
 def _render_effects(ui, text, effects):
-    b'Wrap text in commands to turn on each effect.'
+    """Wrap text in commands to turn on each effect."""
     if not text:
         return text
     if ui._terminfoparams:
diff --git a/mercurial/changelog.py b/mercurial/changelog.py
--- a/mercurial/changelog.py
+++ b/mercurial/changelog.py
@@ -405,7 +405,7 @@
         self._copiesstorage = opener.options.get(b'copies-storage')
 
     def delayupdate(self, tr):
-        b"delay visibility of index updates to other readers"
+        """delay visibility of index updates to other readers"""
 
         if not self._delayed:
             if len(self) == 0:
@@ -423,7 +423,7 @@
         tr.addfinalize(b'cl-%i' % id(self), self._finalize)
 
     def _finalize(self, tr):
-        b"finalize index updates"
+        """finalize index updates"""
         self._delayed = False
         self.opener = self._realopener
         # move redirected index data back into place
@@ -443,7 +443,8 @@
         self._enforceinlinesize(tr)
 
     def _writepending(self, tr):
-        b"create a file containing the unfinalized state for pretxnchangegroup"
+        """create a file containing the unfinalized state for
+        pretxnchangegroup"""
         if self._delaybuf:
             # make a temporary copy of the index
             fp1 = self._realopener(self.indexfile)
diff --git a/hgext/rebase.py b/hgext/rebase.py
--- a/hgext/rebase.py
+++ b/hgext/rebase.py
@@ -1497,7 +1497,7 @@
 
 
 def rebasenode(repo, rev, p1, base, collapse, dest, wctx):
-    b'Rebase a single revision rev on top of p1 using base as merge ancestor'
+    """Rebase a single revision rev on top of p1 using base as merge ancestor"""
     # Merge phase
     # Update to destination and merge it with local
     if wctx.isinmemory():
@@ -1853,7 +1853,7 @@
 
 
 def isagitpatch(repo, patchname):
-    b'Return true if the given patch is in git format'
+    """Return true if the given patch is in git format"""
     mqpatch = os.path.join(repo.mq.path, patchname)
     for line in patch.linereader(open(mqpatch, b'rb')):
         if line.startswith(b'diff --git'):
@@ -1862,7 +1862,7 @@
 
 
 def updatemq(repo, state, skipped, **opts):
-    b'Update rebased mq patches - finalize and then import them'
+    """Update rebased mq patches - finalize and then import them"""
     mqrebase = {}
     mq = repo.mq
     original_series = mq.fullseries[:]
@@ -1916,7 +1916,7 @@
 
 
 def storecollapsemsg(repo, collapsemsg):
-    b'Store the collapse message to allow recovery'
+    """Store the collapse message to allow recovery"""
     collapsemsg = collapsemsg or b''
     f = repo.vfs(b"last-message.txt", b"w")
     f.write(b"%s\n" % collapsemsg)
@@ -1924,12 +1924,12 @@
 
 
 def clearcollapsemsg(repo):
-    b'Remove collapse message file'
+    """Remove collapse message file"""
     repo.vfs.unlinkpath(b"last-message.txt", ignoremissing=True)
 
 
 def restorecollapsemsg(repo, isabort):
-    b'Restore previously stored collapse message'
+    """Restore previously stored collapse message"""
     try:
         f = repo.vfs(b"last-message.txt")
         collapsemsg = f.readline().strip()
@@ -1946,7 +1946,7 @@
 
 
 def clearstatus(repo):
-    b'Remove the status files'
+    """Remove the status files"""
     # Make sure the active transaction won't write the state file
     tr = repo.currenttransaction()
     if tr:
@@ -2127,7 +2127,7 @@
 
 
 def pullrebase(orig, ui, repo, *args, **opts):
-    b'Call rebase after pull if the latter has been invoked with --rebase'
+    """Call rebase after pull if the latter has been invoked with --rebase"""
     if opts.get('rebase'):
         if ui.configbool(b'commands', b'rebase.requiredest'):
             msg = _(b'rebase destination required by configuration')
diff --git a/hgext/hgk.py b/hgext/hgk.py
--- a/hgext/hgk.py
+++ b/hgext/hgk.py
@@ -373,7 +373,7 @@
     helpcategory=command.CATEGORY_CHANGE_NAVIGATION,
 )
 def view(ui, repo, *etc, **opts):
-    b"start interactive history viewer"
+    """start interactive history viewer"""
     opts = pycompat.byteskwargs(opts)
     os.chdir(repo.root)
     optstr = b' '.join(
diff --git a/hgext/convert/p4.py b/hgext/convert/p4.py
--- a/hgext/convert/p4.py
+++ b/hgext/convert/p4.py
@@ -24,7 +24,7 @@
 
 
 def loaditer(f):
-    b"Yield the dictionary objects generated by p4"
+    """Yield the dictionary objects generated by p4"""
     try:
         while True:
             d = marshal.load(f)
@@ -105,7 +105,7 @@
         self.revmap = revmap
 
     def _parse_view(self, path):
-        b"Read changes affecting the path"
+        """Read changes affecting the path"""
         cmd = b'p4 -G changes -s submitted %s' % procutil.shellquote(path)
         stdout = procutil.popen(cmd, mode=b'rb')
         p4changes = {}
@@ -116,7 +116,7 @@
         return p4changes
 
     def _parse(self, ui, path):
-        b"Prepare list of P4 filenames and revisions to import"
+        """Prepare list of P4 filenames and revisions to import"""
         p4changes = {}
         changeset = {}
         files_map = {}
diff --git a/hgext/convert/cvsps.py b/hgext/convert/cvsps.py
--- a/hgext/convert/cvsps.py
+++ b/hgext/convert/cvsps.py
@@ -110,7 +110,7 @@
     _scache = {}
 
     def scache(s):
-        b"return a shared version of a string"
+        """return a shared version of a string"""
         return _scache.setdefault(s, s)
 
     ui.status(_(b'collecting CVS rlog\n'))
@@ -711,7 +711,7 @@
     # Sort files in each changeset
 
     def entitycompare(l, r):
-        b'Mimic cvsps sorting order'
+        """Mimic cvsps sorting order"""
         l = l.file.split(b'/')
         r = r.file.split(b'/')
         nl = len(l)
diff --git a/hgdemandimport/demandimportpy2.py b/hgdemandimport/demandimportpy2.py
--- a/hgdemandimport/demandimportpy2.py
+++ b/hgdemandimport/demandimportpy2.py
@@ -303,18 +303,18 @@
 
 
 def enable():
-    "enable global demand-loading of modules"
+    """enable global demand-loading of modules"""
     builtins.__import__ = _demandimport
 
 
 def disable():
-    "disable global demand-loading of modules"
+    """disable global demand-loading of modules"""
     builtins.__import__ = _origimport
 
 
 @contextmanager
 def deactivated():
-    "context manager for disabling demandimport in 'with' blocks"
+    """context manager for disabling demandimport in 'with' blocks"""
     demandenabled = isenabled()
     if demandenabled:
         disable()



To: mharbison72, martinvonz, #hg-reviewers
Cc: mercurial-devel, spectral


More information about the Mercurial-devel mailing list