Patchwork D2280: remotenames: port partway to python3

login
register
mail settings
Submitter phabricator
Date Feb. 15, 2018, 2:18 p.m.
Message ID <differential-rev-PHID-DREV-z6wdama5jrb3efgi5wxb-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/27977/
State Superseded
Headers show

Comments

phabricator - Feb. 15, 2018, 2:18 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  test-logexchange.t doesn't pass after this, but at least the
  remotenames extension can be imported.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/remotenames.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - Feb. 15, 2018, 2:19 p.m.
durin42 added inline comments.

INLINE COMMENTS

> remotenames.py:25-28
> +try:
> +    from UserDict import DictMixin
> +except ImportError:
> +    from collections import MutableMapping as DictMixin

This import style irritates the import checker. We could do

try

  import UserDict
  dictmixin = DictMixin

except

  import collections
  dictmixin = collections.MutableMapping

would that be preferable?

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: mercurial-devel
Yuya Nishihara - Feb. 15, 2018, 2:38 p.m.
"would that be preferable?"

Perhaps. We'll need that anyway to get around demandimport.
phabricator - Feb. 15, 2018, 2:38 p.m.
yuja added a comment.


  "would that be preferable?"
  
  Perhaps. We'll need that anyway to get around demandimport.

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - Feb. 15, 2018, 3:47 p.m.
durin42 added a comment.


  In https://phab.mercurial-scm.org/D2280#37674, @yuja wrote:
  
  > "would that be preferable?"
  >
  > Perhaps. We'll need that anyway to get around demandimport.
  
  
  I don't think we do (python3 demandimport is slightly nicer in this regard), but I've done it anyway since it helps the import checker.

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - Feb. 16, 2018, 8:06 a.m.
dlax added inline comments.

INLINE COMMENTS

> remotenames.py:30
> +    import collections
> +    dictmixin = collections.MutableMapping
>  

`collections.MutableMapping` exists on Python2 as well (from 2.6 apparently), can't we use it?

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: dlax, yuja, mercurial-devel
phabricator - Feb. 16, 2018, 10:04 p.m.
durin42 added a comment.


  Updated

REPOSITORY
  rHG Mercurial

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

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

Patch

diff --git a/hgext/remotenames.py b/hgext/remotenames.py
--- a/hgext/remotenames.py
+++ b/hgext/remotenames.py
@@ -22,7 +22,10 @@ 
 
 from __future__ import absolute_import
 
-import UserDict
+try:
+    from UserDict import DictMixin
+except ImportError:
+    from collections import MutableMapping as DictMixin
 
 from mercurial.i18n import _
 
@@ -57,7 +60,7 @@ 
     default=True,
 )
 
-class lazyremotenamedict(UserDict.DictMixin):
+class lazyremotenamedict(DictMixin):
     """
     Read-only dict-like Class to lazily resolve remotename entries
 
@@ -110,6 +113,18 @@ 
         else:
             raise KeyError()
 
+    def __iter__(self):
+        return iter(self.potentialentries)
+
+    def __len__(self):
+        return len(self.potentialentries)
+
+    def __setitem__(self):
+        raise NotImplementedError
+
+    def __delitem__(self):
+        raise NotImplementedError
+
     def _fetchandcache(self, key):
         if key in self.cache:
             return self.cache[key]