Patchwork D2847: remotenames: work around move of ABCs in collections

login
register
mail settings
Submitter phabricator
Date March 13, 2018, 10:14 p.m.
Message ID <differential-rev-PHID-DREV-t5sbvxg5gdzqsxyxo4yc-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/29463/
State Superseded
Headers show

Comments

phabricator - March 13, 2018, 10:14 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This starts warning in Python 3.7, and will break in 3.8.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  hgext/remotenames.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - March 14, 2018, 1:55 p.m.
yuja added a comment.


  Could be either `import collections.abc` or adding `collections.abc` to
  `list_stdlib_modules`.

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: yuja, mercurial-devel
phabricator - March 14, 2018, 5:19 p.m.
durin42 added a comment.


  In https://phab.mercurial-scm.org/D2847#45947, @yuja wrote:
  
  > Could be either `import collections.abc` or adding `collections.abc` to
  >  `list_stdlib_modules`.
  
  
  Sadly, neither worked :(
  
  The import checker currently bans /all/ `from ... import ...` statements on stdlib modules (sigh, probably my fault), and `import collections.abc` goes sideways on Python 2. What I've done seems to work though...

REPOSITORY
  rHG Mercurial

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

To: durin42, #hg-reviewers
Cc: 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,12 @@ 
 
 from __future__ import absolute_import
 
-import collections
+try:
+    from collections import abc
+    MutableMapping = abc.MutableMapping
+except ImportError:
+    import collections
+    MutableMapping = collections.MutableMapping
 
 from mercurial.i18n import _
 
@@ -56,7 +61,7 @@ 
     default=True,
 )
 
-class lazyremotenamedict(collections.MutableMapping):
+class lazyremotenamedict(MutableMapping):
     """
     Read-only dict-like Class to lazily resolve remotename entries