|
|
|
@ -228,24 +228,41 @@ class BuiltinPyTests(unittest.TestCase):
|
|
|
|
|
src = open(src_path, 'r').read()
|
|
|
|
|
|
|
|
|
|
is_unclean = False
|
|
|
|
|
be_strict = not self.__modname.endswith('_test')
|
|
|
|
|
unclean_lineno = -1
|
|
|
|
|
for lineno, line in enumerate(src.splitlines(), 1):
|
|
|
|
|
if re.match(r'^#\s*mypy:\s*skip-file\s*$', line):
|
|
|
|
|
self.skipTest('mypy disabled for this file')
|
|
|
|
|
m = re.match(r'^#\s*mypy:\s*([a-z\-]+)\s*$', line)
|
|
|
|
|
if m is not None:
|
|
|
|
|
if m.group(1) == 'skip-file':
|
|
|
|
|
self.skipTest('mypy disabled for this file')
|
|
|
|
|
elif m.group(1) == 'strict':
|
|
|
|
|
be_strict = True
|
|
|
|
|
elif m.group(1) == 'loose':
|
|
|
|
|
be_strict = False
|
|
|
|
|
else:
|
|
|
|
|
self.fail("Invalid mypy directive '%s'" % m.group(1))
|
|
|
|
|
|
|
|
|
|
if re.match(r'^#\s*TODO:\s*mypy-unclean\s*$', line):
|
|
|
|
|
is_unclean = True
|
|
|
|
|
unclean_lineno = lineno
|
|
|
|
|
|
|
|
|
|
be_pedantic = self.__pedantic or not is_unclean
|
|
|
|
|
be_strict = self.__pedantic or be_strict
|
|
|
|
|
|
|
|
|
|
mypy_ini_path = os.path.abspath(os.path.join(os.path.dirname(__file__), 'mypy.ini'))
|
|
|
|
|
mypy_argv = [
|
|
|
|
|
os.path.join(os.environ['VIRTUAL_ENV'], 'bin', 'mypy'),
|
|
|
|
|
'--config-file', mypy_ini_path,
|
|
|
|
|
'--cache-dir=%s' % os.path.join(LIBDIR, 'mypy-cache'),
|
|
|
|
|
'--show-traceback',
|
|
|
|
|
'-m', self.__modname,
|
|
|
|
|
]
|
|
|
|
|
|
|
|
|
|
if be_strict:
|
|
|
|
|
mypy_argv.append('--disallow-untyped-defs')
|
|
|
|
|
|
|
|
|
|
proc = subprocess.run(
|
|
|
|
|
[os.path.join(os.environ['VIRTUAL_ENV'], 'bin', 'mypy'),
|
|
|
|
|
'--config-file', mypy_ini_path,
|
|
|
|
|
'--cache-dir=%s' % os.path.join(LIBDIR, 'mypy-cache'),
|
|
|
|
|
'--show-traceback',
|
|
|
|
|
'-m', self.__modname,
|
|
|
|
|
],
|
|
|
|
|
mypy_argv,
|
|
|
|
|
cwd=LIBDIR,
|
|
|
|
|
env={
|
|
|
|
|
'MYPYPATH': SITE_PACKAGES_DIR,
|
|
|
|
|