diff --git a/mypy/myunit/__main__.py b/mypy/myunit/__main__.py index 34098d40648d..78ef01f6012f 100644 --- a/mypy/myunit/__main__.py +++ b/mypy/myunit/__main__.py @@ -6,4 +6,13 @@ from mypy.myunit import main +# In Python 3.3, mypy.__path__ contains a relative path to the mypy module +# (whereas in later Python versions it contains an absolute path). Because the +# test runner changes directories, this breaks non-toplevel mypy imports. We +# fix that problem by fixing up the path to be absolute here. +import os.path +import mypy +# User-defined packages always have __path__ attributes, but mypy doesn't know that. +mypy.__path__ = [os.path.abspath(p) for p in mypy.__path__] # type: ignore + main() diff --git a/mypy/test/data/check-fastparse.test b/mypy/test/data/check-fastparse.test new file mode 100644 index 000000000000..192fa5ee482e --- /dev/null +++ b/mypy/test/data/check-fastparse.test @@ -0,0 +1,25 @@ +[case testFastParseSyntaxError] +# flags: fast-parser +1 + # E: invalid syntax + +[case testFastParseTypeCommentSyntaxError] +# flags: fast-parser +x = None # type: a : b # E: syntax error in type comment + +[case testFastParseInvalidTypeComment] +# flags: fast-parser +x = None # type: a + b # E: invalid type comment + +-- Function type comments are attributed to the function def line. +-- This happens in both parsers. +[case testFastParseFunctionAnnotationSyntaxError] +# flags: fast-parser +def f(): # E: syntax error in type comment + # type: None -> None + pass + +[case testFastParseInvalidFunctionAnnotation] +# flags: fast-parser +def f(): # E: invalid type comment + # type: (a + b) -> None + pass diff --git a/mypy/test/testcheck.py b/mypy/test/testcheck.py index 412693a39acb..b7975e3a8cc4 100644 --- a/mypy/test/testcheck.py +++ b/mypy/test/testcheck.py @@ -57,6 +57,7 @@ 'check-flags.test', 'check-incremental.test', 'check-bound.test', + 'check-fastparse.test', ] diff --git a/runtests.py b/runtests.py index c82fd0b92e83..82b42c3f58a4 100755 --- a/runtests.py +++ b/runtests.py @@ -155,7 +155,7 @@ def add_basic(driver: Driver) -> None: driver.add_mypy('legacy myunit script', 'scripts/myunit') driver.add_flake8('legacy myunit script', 'scripts/myunit') # needs typed_ast installed: - # driver.add_mypy('fast-parse', '--fast-parse', 'samples/hello.py') + driver.add_mypy('fast-parse', '--fast-parse', 'samples/hello.py') def add_selftypecheck(driver: Driver) -> None: @@ -184,10 +184,7 @@ def add_imports(driver: Driver) -> None: mod = file_to_module(f) if '.test.data.' in mod: continue - # Don't check the importability of the fastparse module because it - # requires typed_ast which may not be available (but which we don't - # want to have an explicit dependency on yet) - if not mod.endswith('.__main__') and not mod.endswith('.fastparse'): + if not mod.endswith('.__main__'): driver.add_python_string('import %s' % mod, 'import %s' % mod) driver.add_flake8('module %s' % mod, f) diff --git a/test-requirements.txt b/test-requirements.txt index 39304807fbc7..47744fe21aac 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1 +1,2 @@ flake8 +typed-ast