D6718: repository: suppress typing errors on functions without arguments

indygreg (Gregory Szorc) phabricator at mercurial-scm.org
Sun Aug 4 19:53:09 UTC 2019


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

REVISION SUMMARY
  zope.interface uses class magic to define interfaces. Mypy doesn't
  like the methods without arguments and raises a warning for the
  dozens of them in repository.py.
  
  This commit adds type annotation comments to silence the error.
  TBH I'm not sure if this is the best way to do this. But it does
  get the job done. We may have to revisit once we add proper type
  annotations to this file. For now, it makes mypy's output far
  less verbose.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/repository.py

CHANGE DETAILS

diff --git a/mercurial/repository.py b/mercurial/repository.py
--- a/mercurial/repository.py
+++ b/mercurial/repository.py
@@ -55,7 +55,7 @@
     """
     ui = interfaceutil.Attribute("""ui.ui instance""")
 
-    def url():
+    def url():  # type: ignore
         """Returns a URL string representing this peer.
 
         Currently, implementations expose the raw URL used to construct the
@@ -67,23 +67,23 @@
         value.
         """
 
-    def local():
+    def local():  # type: ignore
         """Returns a local repository instance.
 
         If the peer represents a local repository, returns an object that
         can be used to interface with it. Otherwise returns ``None``.
         """
 
-    def peer():
+    def peer():  # type: ignore
         """Returns an object conforming to this interface.
 
         Most implementations will ``return self``.
         """
 
-    def canpush():
+    def canpush():  # type: ignore
         """Returns a boolean indicating if this peer can be pushed to."""
 
-    def close():
+    def close():  # type: ignore
         """Close the connection to this peer.
 
         This is called when the peer will no longer be used. Resources
@@ -117,20 +117,20 @@
     methods commonly call wire protocol commands of the same name.
     """
 
-    def branchmap():
+    def branchmap():  # type: ignore
         """Obtain heads in named branches.
 
         Returns a dict mapping branch name to an iterable of nodes that are
         heads on that branch.
         """
 
-    def capabilities():
+    def capabilities():  # type: ignore
         """Obtain capabilities of the peer.
 
         Returns a set of string capabilities.
         """
 
-    def clonebundles():
+    def clonebundles():  # type: ignore
         """Obtains the clone bundles manifest for the repo.
 
         Returns the manifest as unparsed bytes.
@@ -148,7 +148,7 @@
         Returns a generator of bundle data.
         """
 
-    def heads():
+    def heads():  # type: ignore
         """Determine all known head revisions in the peer.
 
         Returns an iterable of binary nodes.
@@ -185,7 +185,7 @@
         namespace.
         """
 
-    def stream_out():
+    def stream_out():  # type: ignore
         """Obtain streaming clone data.
 
         Successful result should be a generator of data chunks.
@@ -262,7 +262,7 @@
         until all command requests have been issued.
         """
 
-    def sendcommands():
+    def sendcommands():  # type: ignore
         """Trigger submission of queued command requests.
 
         Not all transports submit commands as soon as they are requested to
@@ -272,7 +272,7 @@
         When called, no more new commands may be issued with this executor.
         """
 
-    def close():
+    def close():  # type: ignore
         """Signal that this command request is finished.
 
         When called, no more new commands may be issued. All outstanding
@@ -295,7 +295,7 @@
         """True if the peer cannot receive large argument value for commands."""
     )
 
-    def commandexecutor():
+    def commandexecutor():  # type: ignore
         """A context manager that resolves to an ipeercommandexecutor.
 
         The object this resolves to can be used to issue command requests
@@ -439,7 +439,7 @@
     in the index.
     """
 
-    def __len__():
+    def __len__():  # type: ignore
         """The total number of revisions."""
 
     def __getitem__(rev):
@@ -491,10 +491,10 @@
     * DAG data (storing and querying the relationship between nodes).
     * Metadata to facilitate storage.
     """
-    def __len__():
+    def __len__():  # type: ignore
         """Obtain the number of revisions stored for this file."""
 
-    def __iter__():
+    def __iter__():  # type: ignore
         """Iterate over revision numbers for this file."""
 
     def hasnode(node):
@@ -770,7 +770,7 @@
 class ifilestorage(ifileindex, ifiledata, ifilemutation):
     """Complete storage interface for a single tracked file."""
 
-    def files():
+    def files():  # type: ignore
         """Obtain paths that are backing storage for this file.
 
         TODO this is used heavily by verify code and there should probably
@@ -847,7 +847,7 @@
         directory is removed from the collection.
         """
 
-    def __iter__():
+    def __iter__():  # type: ignore
         """Iterate over the directories in this collection of paths."""
 
     def __contains__(path):
@@ -876,10 +876,10 @@
         Raises ``KeyError`` if the path does not exist in the manifest.
         """
 
-    def __len__():
+    def __len__():  # type: ignore
         """Return the number of entries in the manifest."""
 
-    def __nonzero__():
+    def __nonzero__():  # type: ignore
         """Returns True if the manifest has entries, False otherwise."""
 
     __bool__ = __nonzero__
@@ -900,13 +900,13 @@
         Raises ``KeyError`` if the path is not in the manifest.
         """
 
-    def __iter__():
+    def __iter__():  # type: ignore
         """Iterate over paths in the manifest."""
 
-    def iterkeys():
+    def iterkeys():  # type: ignore
         """Iterate over paths in the manifest."""
 
-    def keys():
+    def keys():  # type: ignore
         """Obtain a list of paths in the manifest."""
 
     def filesnotin(other, match=None):
@@ -918,7 +918,7 @@
         Returns a set of paths.
         """
 
-    def dirs():
+    def dirs():  # type: ignore
         """Returns an object implementing the ``idirs`` interface."""
 
     def hasdir(dir):
@@ -969,23 +969,23 @@
     def flags(path, default=''):
         """Return the flags value for a path or a default value if missing."""
 
-    def copy():
+    def copy():  # type: ignore
         """Return a copy of this manifest."""
 
-    def items():
+    def items():  # type: ignore
         """Returns an iterable of (path, node) for items in this manifest."""
 
-    def iteritems():
+    def iteritems():  # type: ignore
         """Identical to items()."""
 
-    def iterentries():
+    def iterentries():  # type: ignore
         """Returns an iterable of (path, node, flags) for this manifest.
 
         Similar to ``iteritems()`` except items are a 3-tuple and include
         flags.
         """
 
-    def text():
+    def text():  # type: ignore
         """Obtain the raw data representation for this manifest.
 
         Result is used to create a manifest revision.
@@ -1009,7 +1009,7 @@
     as part of a larger interface.
     """
 
-    def new():
+    def new():  # type: ignore
         """Obtain a new manifest instance.
 
         Returns an object conforming to the ``imanifestrevisionwritable``
@@ -1017,7 +1017,7 @@
         ``imanifestlog`` collection as this instance.
         """
 
-    def copy():
+    def copy():  # type: ignore
         """Obtain a copy of this manifest instance.
 
         Returns an object conforming to the ``imanifestrevisionwritable``
@@ -1025,7 +1025,7 @@
         ``imanifestlog`` collection as this instance.
         """
 
-    def read():
+    def read():  # type: ignore
         """Obtain the parsed manifest data structure.
 
         The returned object conforms to the ``imanifestdict`` interface.
@@ -1034,7 +1034,7 @@
 class imanifestrevisionstored(imanifestrevisionbase):
     """Interface representing a manifest revision committed to storage."""
 
-    def node():
+    def node():  # type: ignore
         """The binary node for this manifest."""
 
     parents = interfaceutil.Attribute(
@@ -1122,10 +1122,10 @@
         TODO this doesn't feel appropriate for the storage interface.
         """)
 
-    def __len__():
+    def __len__():  # type: ignore
         """Obtain the number of revisions stored for this manifest."""
 
-    def __iter__():
+    def __iter__():  # type: ignore
         """Iterate over revision numbers for this manifest."""
 
     def rev(node):
@@ -1212,13 +1212,13 @@
         See the documentation in ``ifilemutation`` for more.
         """
 
-    def checksize():
+    def checksize():  # type: ignore
         """Obtain the expected sizes of backing files.
 
         TODO this is used by verify and it should not be part of the interface.
         """
 
-    def files():
+    def files():  # type: ignore
         """Obtain paths that are backing storage for this manifest.
 
         TODO this is used by verify and there should probably be a better API
@@ -1317,7 +1317,7 @@
         TODO formalize interface for returned object.
         """
 
-    def clearcaches():
+    def clearcaches():  # type: ignore
         """Clear caches associated with this collection."""
 
     def rev(node):
@@ -1453,13 +1453,13 @@
     names = interfaceutil.Attribute(
         """A ``namespaces`` instance.""")
 
-    def close():
+    def close():  # type: ignore
         """Close the handle on this repository."""
 
-    def peer():
+    def peer():  # type: ignore
         """Obtain an object conforming to the ``peer`` interface."""
 
-    def unfiltered():
+    def unfiltered():  # type: ignore
         """Obtain an unfiltered/raw view of this repo."""
 
     def filtered(name, visibilityexceptions=None):
@@ -1495,16 +1495,16 @@
     def __contains__(changeid):
         """Whether a changeset exists."""
 
-    def __nonzero__():
+    def __nonzero__():  # type: ignore
         """Always returns True."""
         return True
 
     __bool__ = __nonzero__
 
-    def __len__():
+    def __len__():  # type: ignore
         """Returns the number of changesets in the repo."""
 
-    def __iter__():
+    def __iter__():  # type: ignore
         """Iterate over revisions in the changelog."""
 
     def revs(expr, *args):
@@ -1522,19 +1522,19 @@
     def anyrevs(specs, user=False, localalias=None):
         """Find revisions matching one of the given revsets."""
 
-    def url():
+    def url():  # type: ignore
         """Returns a string representing the location of this repo."""
 
     def hook(name, throw=False, **args):
         """Call a hook."""
 
-    def tags():
+    def tags():  # type: ignore
         """Return a mapping of tag to node."""
 
     def tagtype(tagname):
         """Return the type of a given tag."""
 
-    def tagslist():
+    def tagslist():  # type: ignore
         """Return a list of tags ordered by revision."""
 
     def nodetags(node):
@@ -1543,10 +1543,10 @@
     def nodebookmarks(node):
         """Return the list of bookmarks pointing to the specified node."""
 
-    def branchmap():
+    def branchmap():  # type: ignore
         """Return a mapping of branch to heads in that branch."""
 
-    def revbranchcache():
+    def revbranchcache():  # type: ignore
         pass
 
     def branchtip(branchtip, ignoremissing=False):
@@ -1564,17 +1564,17 @@
         Returns a list of bools.
         """
 
-    def local():
+    def local():  # type: ignore
         """Whether the repository is local."""
         return True
 
-    def publishing():
+    def publishing():  # type: ignore
         """Whether the repository is a publishing repository."""
 
-    def cancopy():
+    def cancopy():  # type: ignore
         pass
 
-    def shared():
+    def shared():  # type: ignore
         """The type of shared repository or None."""
 
     def wjoin(f, *insidef):
@@ -1586,7 +1586,7 @@
     def filectx(path, changeid=None, fileid=None):
         """Obtain a filectx for the given file revision."""
 
-    def getcwd():
+    def getcwd():  # type: ignore
         """Obtain the current working directory from the dirstate."""
 
     def pathto(f, cwd=None):
@@ -1604,16 +1604,16 @@
     def wwritedata(filename, data):
         """Resolve data for writing to the wvfs, using data filters."""
 
-    def currenttransaction():
+    def currenttransaction():  # type: ignore
         """Obtain the current transaction instance or None."""
 
     def transaction(desc, report=None):
         """Open a new transaction to write to the repository."""
 
-    def undofiles():
+    def undofiles():  # type: ignore
         """Returns a list of (vfs, path) for files to undo transactions."""
 
-    def recover():
+    def recover():  # type: ignore
         """Roll back an interrupted transaction."""
 
     def rollback(dryrun=False, force=False):
@@ -1625,19 +1625,19 @@
     def updatecaches(tr=None, full=False):
         """Warm repo caches."""
 
-    def invalidatecaches():
+    def invalidatecaches():  # type: ignore
         """Invalidate cached data due to the repository mutating."""
 
-    def invalidatevolatilesets():
+    def invalidatevolatilesets():  # type: ignore
         pass
 
-    def invalidatedirstate():
+    def invalidatedirstate():  # type: ignore
         """Invalidate the dirstate."""
 
     def invalidate(clearfilecache=False):
         pass
 
-    def invalidateall():
+    def invalidateall():  # type: ignore
         pass
 
     def lock(wait=True):
@@ -1646,7 +1646,7 @@
     def wlock(wait=True):
         """Lock the non-store parts of the repository."""
 
-    def currentwlock():
+    def currentwlock():  # type: ignore
         """Return the wlock if it's held or None."""
 
     def checkcommitpatterns(wctx, vdirs, match, status, fail):
@@ -1659,10 +1659,10 @@
     def commitctx(ctx, error=False, origctx=None):
         """Commit a commitctx instance to the repository."""
 
-    def destroying():
+    def destroying():  # type: ignore
         """Inform the repository that nodes are about to be destroyed."""
 
-    def destroyed():
+    def destroyed():  # type: ignore
         """Inform the repository that nodes have been destroyed."""
 
     def status(node1='.', node2=None, match=None, ignored=False,
@@ -1672,10 +1672,10 @@
     def addpostdsstatus(ps):
         pass
 
-    def postdsstatus():
+    def postdsstatus():  # type: ignore
         pass
 
-    def clearpostdsstatus():
+    def clearpostdsstatus():  # type: ignore
         pass
 
     def heads(start=None):
@@ -1794,7 +1794,7 @@
     could wrap the encoded object data in ``wireprototypes.encodedresponse``
     instances to avoid this overhead.
     """
-    def __enter__():
+    def __enter__():  # type: ignore
         """Marks the instance as active.
 
         Should return self.
@@ -1831,7 +1831,7 @@
         instance.
         """
 
-    def lookup():
+    def lookup():  # type: ignore
         """Attempt to resolve an entry in the cache.
 
         The instance is instructed to look for the cache key that it was
@@ -1860,7 +1860,7 @@
         ``yield obj``.
         """
 
-    def onfinished():
+    def onfinished():  # type: ignore
         """Called after all objects have been emitted from the command function.
 
         Implementations should return an iterator of objects to forward to



To: indygreg, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list