Patchwork D2433: context: remove basectx.__int__ (API)

login
register
mail settings
Submitter phabricator
Date Feb. 24, 2018, 7:31 p.m.
Message ID <differential-rev-PHID-DREV-nvx5kpsieuy52xeuryyv-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28338/
State Superseded
Headers show

Comments

phabricator - Feb. 24, 2018, 7:31 p.m.
indygreg created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  basectx is the only type in the repo having __int__ implemented.
  
  This magic method can result in unexpected coercion. Furthermore,
  having it implemented is wrong for some contexts, since rev() may
  return None in some cases.
  
  Previous commits removed known cases in core where contexts are
  coerced to integers. So let's delete basectx.__int__.
  
  This commit is a bit dangerous. While the test suite passes, there
  are likely still some callers in core that rely on __int__ that
  don't have test coverage. An alternative would be to issue a
  deprecation warning and let this bake for a few releases.
  
  .. api::
  
    context.basectx no longer implements __int__. Context instances
    will no longer cast to ints. Consumers should call ``ctx.rev()``
    instead.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/context.py

CHANGE DETAILS




To: indygreg, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - Feb. 25, 2018, 1:39 a.m.
"While the test suite passes, there are likely still some callers in core
that rely on __int__ that don't have test coverage."

I think we can fix them in next 2 months. Queued with delight, thanks.
phabricator - Feb. 25, 2018, 1:39 a.m.
yuja added a comment.


  "While the test suite passes, there are likely still some callers in core
  that rely on __int__ that don't have test coverage."
  
  I think we can fix them in next 2 months. Queued with delight, thanks.

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -78,9 +78,6 @@ 
 
     __str__ = encoding.strmethod(__bytes__)
 
-    def __int__(self):
-        return self.rev()
-
     def __repr__(self):
         return r"<%s %s>" % (type(self).__name__, str(self))