Patchwork [Bug,4920] New: TypeError: unsupported operand type(s) for -: '_demandmod' and 'int'

login
register
mail settings
Submitter mercurial-bugs@selenic.com
Date Oct. 26, 2015, 9:48 p.m.
Message ID <bug-4920-285@https.bz.mercurial-scm.org/>
Download mbox | patch
Permalink /patch/11247/
State Changes Requested
Headers show

Comments

mercurial-bugs@selenic.com - Oct. 26, 2015, 9:48 p.m.
https://bz.mercurial-scm.org/show_bug.cgi?id=4920

            Bug ID: 4920
           Summary: TypeError: unsupported operand type(s) for -:
                    '_demandmod' and 'int'
           Product: Mercurial
           Version: 3.5.2
          Hardware: PC
                OS: Linux
            Status: UNCONFIRMED
          Severity: bug
          Priority: normal
         Component: Mercurial
          Assignee: bugzilla@selenic.com
          Reporter: gabor.stefanik@nng.com
                CC: mercurial-devel@selenic.com

Ran into this when trying to run Mercurial inside an unusual Python virtual
environment. Google shows a few other users running into it as well, though
very hard to reproduce. Apparently it occurs if the Python regex library is
loaded after demandimport is active, and perhaps even then only on certain
Python versions.

Full backtrace:
  File "/home/repo/nngutils_hg/python27/bin/hg", line 43, in <module>
    mercurial.util.setbinary(fp)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 114, in __getattribute__
    self._load()
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 86, in _load
    mod = _hgextimport(_import, head, globals, locals, None, level)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 55, in _hgextimport
    return importfunc(name, globals, *args)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/util.py",
line 30, in <module>
    cachestat = platform.cachestat
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 114, in __getattribute__
    self._load()
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 86, in _load
    mod = _hgextimport(_import, head, globals, locals, None, level)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 55, in _hgextimport
    return importfunc(name, globals, *args)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/posix.py",
line 206, in <module>
    normcasespec = encoding.normcasespecs.lower
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 114, in __getattribute__
    self._load()
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 86, in _load
    mod = _hgextimport(_import, head, globals, locals, None, level)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 55, in _hgextimport
    return importfunc(name, globals, *args)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/encoding.py",
line 68, in <module>
    except locale.Error:
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 114, in __getattribute__
    self._load()
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 86, in _load
    mod = _hgextimport(_import, head, globals, locals, None, level)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 55, in _hgextimport
    return importfunc(name, globals, *args)
  File "/home/repo/nngutils_hg/python27/lib/python2.7/locale.py", line 182, in
<module>
    _percent_re = re.compile(r'%(?:\((?P<key>.*?)\))?'
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 114, in __getattribute__
    self._load()
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 86, in _load
    mod = _hgextimport(_import, head, globals, locals, None, level)
  File
"/home/repo/nngutils_hg/python27/lib/python2.7/site-packages/mercurial/demandimport.py",
line 55, in _hgextimport
    return importfunc(name, globals, *args)
  File "/home/repo/nngutils_hg/python27/lib/python2.7/re.py", line 222, in
<module>
    _pattern_type = type(sre_compile.compile("", 0))
  File "/home/repo/nngutils_hg/python27/lib/python2.7/sre_compile.py", line
502, in compile
    code = _code(p, flags)
  File "/home/repo/nngutils_hg/python27/lib/python2.7/sre_compile.py", line
484, in _code
    _compile_info(code, p, flags)
  File "/home/repo/nngutils_hg/python27/lib/python2.7/sre_compile.py", line
363, in _compile_info
    lo, hi = pattern.getwidth()
  File "/home/repo/nngutils_hg/python27/lib/python2.7/sre_parse.py", line 174,
in getwidth
    self.width = min(lo, MAXREPEAT - 1), min(hi, MAXREPEAT)
TypeError: unsupported operand type(s) for -: '_demandmod' and 'int'


Fairly easy to fix - '_sre' nees to be added to be the demandimport blacklist.

# HG changeset patch
# User gstefanik
# Date 1445894342 -3600
#      Mon Oct 26 22:19:02 2015 +0100
# Branch hg
# Node ID 21139c6df629cee1ee9d9509da201b6693d80bf3
# Parent  30c5bca51750f0c2950f0d49395a3d28a88da72c
fix _demandmod error on linux

Patch

diff -r 30c5bca51750 -r 21139c6df629 mercurial/demandimport.py
--- a/mercurial/demandimport.py Mon Oct 26 20:21:40 2015 +0100
+++ b/mercurial/demandimport.py Mon Oct 26 22:19:02 2015 +0100
@@ -170,6 +170,7 @@ 
     # raise ImportError if x not defined
     '__main__',
     '_ssl', # conditional imports in the stdlib, issue1964
+    '_sre',
     'rfc822',
     'mimetools',
     # setuptools 8 expects this module to explode early when not on windows