Mercurial > hg
view hgext/closehead.py @ 49652:03792c1ed341
contrib: add a script for adding vendored type stubs to typeshed
I really hate this, but pytype doesn't support PEP 561 and doesn't seem to have
the equivalent of `MYPYPATH` to point to custom stubs. Ignoring the vendored
stubs isn't necessarily harmful, but pytype has been choking on the vendored
attr package after pytype 2022.03.29 with errors like this:
File "/mnt/c/Users/Matt/hg/mercurial/linelog.py", line 52, in __iter__: Built-in function iter was called with the wrong arguments [wrong-arg-types]
Expected: (collection: bytearray)
Actually passed: (collection: mercurial.thirdparty.attr._make._CountingAttr)
File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 143, in pack: Built-in function len was called with the wrong arguments [wrong-arg-types]
Expected: (obj: Sized)
Actually passed: (obj: mercurial.thirdparty.attr._make._CountingAttr)
Attributes of protocol Sized are not implemented on mercurial.thirdparty.attr._make._CountingAttr: __len__
File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 144, in pack: No attribute 'rfind' on mercurial.thirdparty.attr._make._CountingAttr [attribute-error]
File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 146, in pack: Built-in function len was called with the wrong arguments [wrong-arg-types]
Expected: (obj: Sized)
Actually passed: (obj: mercurial.thirdparty.attr._make._CountingAttr)
Attributes of protocol Sized are not implemented on mercurial.thirdparty.attr._make._CountingAttr: __len__
File "/mnt/c/Users/Matt/hg/mercurial/dirstateutils/v2.py", line 152, in pack: No attribute 'v2_data' on mercurial.thirdparty.attr._make._CountingAttr [attribute-error]
File "/mnt/c/Users/Matt/hg/mercurial/util.py", line 2817, in go: unsupported operand type(s) for /: 'count: mercurial.thirdparty.attr._make._CountingAttr' and 'float: float' [unsupported-operands]
No attribute '__truediv__' on 'count: mercurial.thirdparty.attr._make._CountingAttr' or '__rtruediv__' on 'float: float'
Called from (traceback):
line 2981, in __bytes__
This is essentially the same hack we've been using in TortoiseHg to add the
vendored PyQt5 stubs. What I don't understand is pytype *still* generates *.pyi
files under .pytype/pyi/mercurial/thirdparty/attr, even when the package is
explicitly ignored in the pytype command line args. But it avoids the errors,
which means we aren't stuck on pytype==2022.03.29.
https://github.com/google/pytype/issues/151
author | Matt Harbison <matt_harbison@yahoo.com> |
---|---|
date | Wed, 23 Nov 2022 20:50:39 -0500 |
parents | 6000f5b25c9b |
children | 259213382862 |
line wrap: on
line source
# closehead.py - Close arbitrary heads without checking them out first # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. '''close arbitrary heads without checking them out first''' from mercurial.i18n import _ from mercurial import ( bookmarks, cmdutil, context, error, logcmdutil, pycompat, registrar, ) cmdtable = {} command = registrar.command(cmdtable) # Note for extension authors: ONLY specify testedwith = 'ships-with-hg-core' for # extensions which SHIP WITH MERCURIAL. Non-mainline extensions should # be specifying the version(s) of Mercurial they are tested with, or # leave the attribute unspecified. testedwith = b'ships-with-hg-core' commitopts = cmdutil.commitopts commitopts2 = cmdutil.commitopts2 commitopts3 = [(b'r', b'rev', [], _(b'revision to check'), _(b'REV'))] @command( b'close-head|close-heads', commitopts + commitopts2 + commitopts3, _(b'[OPTION]... [REV]...'), helpcategory=command.CATEGORY_CHANGE_MANAGEMENT, inferrepo=True, ) def close_branch(ui, repo, *revs, **opts): """close the given head revisions This is equivalent to checking out each revision in a clean tree and running ``hg commit --close-branch``, except that it doesn't change the working directory. The commit message must be specified with -l or -m. """ def docommit(rev): cctx = context.memctx( repo, parents=[rev, None], text=message, files=[], filectxfn=None, user=opts.get(b'user'), date=opts.get(b'date'), extra=extra, ) tr = repo.transaction(b'commit') ret = repo.commitctx(cctx, True) bookmarks.update(repo, [rev, None], ret) cctx.markcommitted(ret) tr.close() opts = pycompat.byteskwargs(opts) revs += tuple(opts.get(b'rev', [])) revs = logcmdutil.revrange(repo, revs) if not revs: raise error.Abort(_(b'no revisions specified')) heads = [] for branch in repo.branchmap(): heads.extend(repo.branchheads(branch)) heads = {repo[h].rev() for h in heads} for rev in revs: if rev not in heads: raise error.Abort(_(b'revision is not an open head: %d') % rev) message = cmdutil.logmessage(ui, opts) if not message: raise error.Abort(_(b"no commit message specified with -l or -m")) extra = {b'close': b'1'} with repo.wlock(), repo.lock(): for rev in revs: r = repo[rev] branch = r.branch() extra[b'branch'] = branch docommit(r) return 0