From 3d9c9b0d8bf0f2634e5cb9a79346987bdae3bcee Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Wed, 18 Feb 2026 13:01:02 +0000 Subject: [PATCH] Detect partial stub packages --- mypy/nativeparse.py | 11 +++++++---- mypy/test/test_nativeparse.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/mypy/nativeparse.py b/mypy/nativeparse.py index ece6595ecf38..bb13b121a9e6 100644 --- a/mypy/nativeparse.py +++ b/mypy/nativeparse.py @@ -300,7 +300,9 @@ def native_parse( node.path = filename return node, [], [] - b, errors, ignores, import_bytes = parse_to_binary_ast(filename, options, skip_function_bodies) + b, errors, ignores, import_bytes, is_partial_package = parse_to_binary_ast( + filename, options, skip_function_bodies + ) data = ReadBuffer(b) n = read_int(data) state = State(options) @@ -310,6 +312,7 @@ def native_parse( node = MypyFile(defs, imports) node.path = filename + node.is_partial_stub_package = is_partial_package # Merge deserialization errors with parsing errors all_errors = errors + state.errors return node, all_errors, ignores @@ -329,11 +332,11 @@ def read_statements(state: State, data: ReadBuffer, n: int) -> list[Statement]: def parse_to_binary_ast( filename: str, options: Options, skip_function_bodies: bool = False -) -> tuple[bytes, list[dict[str, Any]], TypeIgnores, bytes]: - ast_bytes, errors, ignores, import_bytes = ast_serialize.parse( +) -> tuple[bytes, list[dict[str, Any]], TypeIgnores, bytes, bool]: + ast_bytes, errors, ignores, import_bytes, is_partial_package = ast_serialize.parse( filename, skip_function_bodies, python_version=options.python_version ) - return ast_bytes, errors, ignores, import_bytes + return ast_bytes, errors, ignores, import_bytes, is_partial_package def read_statement(state: State, data: ReadBuffer) -> Statement: diff --git a/mypy/test/test_nativeparse.py b/mypy/test/test_nativeparse.py index c13cd65861b4..13777d59cf4b 100644 --- a/mypy/test/test_nativeparse.py +++ b/mypy/test/test_nativeparse.py @@ -235,7 +235,7 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) -> ] with temp_source("print('hello')") as fnam: - b, _, _, _ = parse_to_binary_ast(fnam, Options()) + b, _, _, _, _ = parse_to_binary_ast(fnam, Options()) assert list(b) == ( [LITERAL_INT, 22, nodes.EXPR_STMT, nodes.CALL_EXPR] + [nodes.NAME_EXPR, LITERAL_STR]