Patchwork D7381: cmdutil: add a pytype annotation to help out some callsites

login
register
mail settings
Submitter phabricator
Date Nov. 14, 2019, 3:52 a.m.
Message ID <differential-rev-PHID-DREV-7w2wacovvwnjepih2ykn-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/43179/
State Superseded
Headers show

Comments

phabricator - Nov. 14, 2019, 3:52 a.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I think we could constrain the values here more than Any, but this
  lets us move forward with typechecking commands.py.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/cmdutil.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Nov. 14, 2019, 9:12 a.m.
dlax added inline comments.

INLINE COMMENTS

> cmdutil.py:3970
>  def readgraftstate(repo, graftstate):
> +    # type: (Any, statemod.cmdstate) -> Dict[bytes, Any]
>      """read the graft state file and return a dict of the data stored in it"""

Wouldn't `-> Dict[bytes, List[bytes]]` be okay? (Not sure why "Any" you're referering to in commit message, though I understand `Dict[bytes, Any]` comes from `state.cmdstate.read()` return type in D7383 <https://phab.mercurial-scm.org/D7383>.)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7381/new/

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

To: durin42, #hg-reviewers
Cc: dlax, mercurial-devel
phabricator - Nov. 14, 2019, 9:15 p.m.
durin42 added inline comments.
durin42 marked an inline comment as done.

INLINE COMMENTS

> dlax wrote in cmdutil.py:3970
> Wouldn't `-> Dict[bytes, List[bytes]]` be okay? (Not sure why "Any" you're referering to in commit message, though I understand `Dict[bytes, Any]` comes from `state.cmdstate.read()` return type in D7383 <https://phab.mercurial-scm.org/D7383>.)

I'm pretty sure that some of the dict values are booleans at the very least?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7381/new/

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

To: durin42, #hg-reviewers, dlax
Cc: dlax, mercurial-devel

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -61,6 +61,15 @@ 
     stringutil,
 )
 
+if not globals():
+    from typing import (
+        Any,
+        Dict,
+    )
+
+    for t in (Any, Dict):
+        assert t
+
 stringio = util.stringio
 
 # templates of common command options
@@ -3958,6 +3967,7 @@ 
 
 
 def readgraftstate(repo, graftstate):
+    # type: (Any, statemod.cmdstate) -> Dict[bytes, Any]
     """read the graft state file and return a dict of the data stored in it"""
     try:
         return graftstate.read()