Read about our upcoming Code of Conduct on this issue

Commit f2e39440 authored by Matt Harbison's avatar Matt Harbison
Browse files

cleanup: fix docstring formatting

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.

Differential Revision: https://phab.mercurial-scm.org/D7539
parent 421ea5772039
......@@ -303,18 +303,18 @@ def isenabled():
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()
......
......@@ -110,7 +110,7 @@ def createlog(ui, directory=None, root=b"", rlog=True, cache=None):
_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 @@ def createchangeset(ui, log, fuzz=60, mergefrom=None, mergeto=None):
# 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)
......
......@@ -24,7 +24,7 @@ from . import common
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 @@ class p4_source(common.converter_source):
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 @@ class p4_source(common.converter_source):
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 = {}
......
......@@ -373,7 +373,7 @@ def revlist(ui, repo, *revs, **opts):
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(
......
......@@ -1497,7 +1497,7 @@ def commitnode(repo, p1, p2, editor, extra, user, date, commitmsg):
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 defineparents(repo, rev, destmap, state, skipped, obsskipped):
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 isagitpatch(repo, patchname):
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 updatemq(repo, state, skipped, **opts):
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 storecollapsemsg(repo, collapsemsg):
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 restorecollapsemsg(repo, isabort):
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 clearrebased(
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')
......
......@@ -405,7 +405,7 @@ class changelog(revlog.revlog):
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 @@ class changelog(revlog.revlog):
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 @@ class changelog(revlog.revlog):
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)
......
......@@ -330,7 +330,7 @@ def _activeeffects(ui):
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 _mergeeffects(text, start, stop):
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:
......
......@@ -1587,7 +1587,7 @@ class workingctx(committablectx):
)
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):
......
......@@ -102,7 +102,7 @@ class patchnode(object):
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 @@ class uiheader(patchnode):
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 uiheader(patchnode):
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 @@ class uihunkline(patchnode):
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 @@ class uihunk(patchnode):
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
)
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
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 @@ class curseschunkselector(object):
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 @@ the following are valid keystrokes:
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 @@ the following are valid keystrokes:
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:
......
......@@ -102,7 +102,7 @@ class request(object):
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:])
......
......@@ -312,13 +312,13 @@ _wide = _sysstr(
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 trim(s, width, ellipsis=b'', leftside=False):
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 lower(s):
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:
......
......@@ -279,7 +279,7 @@ def _picktool(repo, ui, path, binary, symlink, changedelete):
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 _eoltype(data):
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)
......
......@@ -1345,7 +1345,7 @@ def verify(repo, level=None):
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
......
......@@ -24,7 +24,7 @@ class idirstate(interfaceutil.Interface):
"""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.""")
......
......@@ -2093,7 +2093,7 @@ def applyupdates(
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:
......
......@@ -34,17 +34,17 @@ class parser(object):
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 @@ class parser(object):
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 @@ class parser(object):
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 @@ class parser(object):
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)
......
......@@ -1570,7 +1570,7 @@ class hunk(object):
class binhunk(object):
b'A binary patch file.'
"""A binary patch file."""
def __init__(self, lr, fname):
self.text = None
......
......@@ -1528,7 +1528,7 @@ class gitsubrepo(abstractsubrepo):
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:
......
......@@ -653,7 +653,8 @@ class ui(object):
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
......
......@@ -249,7 +249,8 @@ _filtertable = {
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 @@ def shellenviron(environ=None):
"""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:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment