Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions mypy/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ def parse(
parse contents from path `fnam` if `source` is `None`.
"""
if options.native_parser:
import mypy.nativeparse
# Use import from as workaround for cpython#149728 - accessing mypy.nativeparse
# after importing it may fail when this function is called concurrently.
from mypy import nativeparse

ignore_errors = options.ignore_errors or fnam in errors.ignored_files
# If errors are ignored, we can drop many function bodies to speed up type checking.
strip_function_bodies = ignore_errors and not options.preserve_asts
tree, _, _ = mypy.nativeparse.native_parse(
tree, _, _ = nativeparse.native_parse(
fnam, options, source, skip_function_bodies=strip_function_bodies
)
# Set is_stub based on file extension
Expand Down Expand Up @@ -120,9 +122,11 @@ def report_parse_error(error: ParseError, errors: Errors) -> None:

def parse_type_string(expr: StrExpr, options: Options) -> ProperType:
if options.native_parser:
import mypy.nativeparse
# Use a import from as workaround for cpython#149728 - accessing mypy.nativeparse
# after importing it may fail when this function is called concurrently.
from mypy import nativeparse

return mypy.nativeparse.native_parse_type_string(
return nativeparse.native_parse_type_string(
expr.value,
expr.line,
expr.column,
Expand Down
6 changes: 4 additions & 2 deletions mypy/test/testcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import sys
import sysconfig

from mypy.test.config import PREFIX, test_temp_dir
import mypy
from mypy.test.config import test_temp_dir
from mypy.test.data import DataDrivenTestCase, DataSuite
from mypy.test.helpers import (
assert_string_arrays_equal,
Expand Down Expand Up @@ -72,7 +73,8 @@ def test_python_cmdline(testcase: DataDrivenTestCase, step: int) -> None:
env = os.environ.copy()
env.pop("COLUMNS", None)
extra_path = os.path.join(os.path.abspath(test_temp_dir), "pypath")
env["PYTHONPATH"] = PREFIX
# Use the same mypy installation as pytest, including the compiled wheel in CI.
env["PYTHONPATH"] = os.path.dirname(os.path.abspath(mypy.__path__[0]))
if os.path.isdir(extra_path):
env["PYTHONPATH"] += os.pathsep + extra_path
cwd = os.path.join(test_temp_dir, custom_cwd or "")
Expand Down
Loading