Patchwork D7965: py3: catch AttributeError too with ImportError

login
register
mail settings
Submitter phabricator
Date Jan. 21, 2020, 9:47 p.m.
Message ID <differential-rev-PHID-DREV-ss7j2anbkolwtktm4hq4-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/44562/
State Superseded
Headers show

Comments

phabricator - Jan. 21, 2020, 9:47 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Looks like py3 raises AttributeError instead of ImportError. This is caught on
  windows.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/color.py
  mercurial/crecord.py
  tests/hghave.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel, spectral
phabricator - Feb. 5, 2020, 11:21 p.m.
marmoute added a comment.
marmoute accepted this revision.


  Sounds reasonable

REPOSITORY
  rHG Mercurial

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

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

To: pulkit, #hg-reviewers, marmoute
Cc: marmoute, mercurial-devel

Patch

diff --git a/tests/hghave.py b/tests/hghave.py
--- a/tests/hghave.py
+++ b/tests/hghave.py
@@ -669,7 +669,7 @@ 
 
         curses.COLOR_BLUE
         return matchoutput('test -x "`which tic`"', br'')
-    except ImportError:
+    except (ImportError, AttributeError):
         return False
 
 
diff --git a/mercurial/crecord.py b/mercurial/crecord.py
--- a/mercurial/crecord.py
+++ b/mercurial/crecord.py
@@ -62,13 +62,13 @@ 
     import curses.ascii
 
     curses.error
-except ImportError:
+except (ImportError, AttributeError):
     # I have no idea if wcurses works with crecord...
     try:
         import wcurses as curses
 
         curses.error
-    except ImportError:
+    except (ImportError, AttributeError):
         # wcurses is not shipped on Windows by default, or python is not
         # compiled with curses
         curses = False
diff --git a/mercurial/color.py b/mercurial/color.py
--- a/mercurial/color.py
+++ b/mercurial/color.py
@@ -44,7 +44,7 @@ 
         b'cyan': (False, curses.COLOR_CYAN, b''),
         b'white': (False, curses.COLOR_WHITE, b''),
     }
-except ImportError:
+except (ImportError, AttributeError):
     curses = None
     _baseterminfoparams = {}