Patchwork D11500: dirstate: Appease pytype

login
register
mail settings
Submitter phabricator
Date Sept. 28, 2021, 11:43 a.m.
Message ID <differential-rev-PHID-DREV-i2iusxt3h5gnkeqrlfau-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49824/
State Superseded
Headers show

Comments

phabricator - Sept. 28, 2021, 11:43 a.m.
SimonSapin created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  test-check-pytype.t was failing since 98c0408324e6 <https://phab.mercurial-scm.org/rHG98c0408324e6bdf9dc4d306b467167b869092d5a>:
  
    File "/home/simon/projects/hg/mercurial/dirstatemap.py", line 572, in
    addfile: unsupported operand type(s) for &: 'size: None' and
    'rangemask: int' [unsupported-operands]
        No attribute '__and__' on 'size: None' or '__rand__' on 'rangemask: int'
    File "/home/simon/projects/hg/mercurial/dirstatemap.py", line 573, in
    addfile: unsupported operand type(s) for &: 'mtime: None' and
    'rangemask: int' [unsupported-operands]
        No attribute '__and__' on 'mtime: None' or '__rand__' on 'rangemask: int'
  
  `None` is the default value of the `size` and `mtime` parameters of the
  `addfile` method. However, the relevant lines are only used in a code path
  where those defaults are never used. These `size` and `mtime` are passed
  to `DirstateItem.new_normal` which (in the C implementation) calls
  `dirstate_item_new_normal` which uses:
  
    PyArg_ParseTuple(args, "iii", &mode, &size, &mtime)
  
  So `None` values would cause an exception to be raised anyway.
  The new `assert`s only move that exception earlier, and informs pytype
  that we expect `None` to never happen in this code path.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/dirstatemap.py

CHANGE DETAILS




To: SimonSapin, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/dirstatemap.py b/mercurial/dirstatemap.py
--- a/mercurial/dirstatemap.py
+++ b/mercurial/dirstatemap.py
@@ -575,6 +575,8 @@ 
             elif possibly_dirty:
                 item = DirstateItem.new_possibly_dirty()
             else:
+                assert size is not None
+                assert mtime is not None
                 size = size & rangemask
                 mtime = mtime & rangemask
                 item = DirstateItem.new_normal(mode, size, mtime)