Patchwork D6743: perf: handle NameError for `pycompat.foo` when pycompat wasn't imported

login
register
mail settings
Submitter phabricator
Date Aug. 19, 2019, 5:43 p.m.
Message ID <differential-rev-PHID-DREV-f6wh7i4o23l6cr4452tg-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/41350/
State Superseded
Headers show

Comments

phabricator - Aug. 19, 2019, 5:43 p.m.
martinvonz created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  On old Mercurial versions, we won't have a pycompat variable defined,
  and then `pycompat.foo` will raise a NameError.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  contrib/perf.py

CHANGE DETAILS




To: martinvonz, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/contrib/perf.py b/contrib/perf.py
--- a/contrib/perf.py
+++ b/contrib/perf.py
@@ -132,7 +132,7 @@ 
         _maxint = sys.maxsize  # per py3 docs for replacing maxint
     else:
         _maxint = sys.maxint
-except (ImportError, AttributeError):
+except (NameError, ImportError, AttributeError):
     import inspect
     getargspec = inspect.getargspec
     _byteskwargs = identity
@@ -144,11 +144,11 @@ 
 try:
     # 4.7+
     queue = pycompat.queue.Queue
-except (AttributeError, ImportError):
+except (NameError, AttributeError, ImportError):
     # <4.7.
     try:
         queue = pycompat.queue
-    except (AttributeError, ImportError):
+    except (NameError, AttributeError, ImportError):
         queue = util.queue
 
 try: