Skip to content

Commit 3d9c9b0

Browse files
committed
Detect partial stub packages
1 parent 4270ff8 commit 3d9c9b0

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

mypy/nativeparse.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ def native_parse(
300300
node.path = filename
301301
return node, [], []
302302

303-
b, errors, ignores, import_bytes = parse_to_binary_ast(filename, options, skip_function_bodies)
303+
b, errors, ignores, import_bytes, is_partial_package = parse_to_binary_ast(
304+
filename, options, skip_function_bodies
305+
)
304306
data = ReadBuffer(b)
305307
n = read_int(data)
306308
state = State(options)
@@ -310,6 +312,7 @@ def native_parse(
310312

311313
node = MypyFile(defs, imports)
312314
node.path = filename
315+
node.is_partial_stub_package = is_partial_package
313316
# Merge deserialization errors with parsing errors
314317
all_errors = errors + state.errors
315318
return node, all_errors, ignores
@@ -329,11 +332,11 @@ def read_statements(state: State, data: ReadBuffer, n: int) -> list[Statement]:
329332

330333
def parse_to_binary_ast(
331334
filename: str, options: Options, skip_function_bodies: bool = False
332-
) -> tuple[bytes, list[dict[str, Any]], TypeIgnores, bytes]:
333-
ast_bytes, errors, ignores, import_bytes = ast_serialize.parse(
335+
) -> tuple[bytes, list[dict[str, Any]], TypeIgnores, bytes, bool]:
336+
ast_bytes, errors, ignores, import_bytes, is_partial_package = ast_serialize.parse(
334337
filename, skip_function_bodies, python_version=options.python_version
335338
)
336-
return ast_bytes, errors, ignores, import_bytes
339+
return ast_bytes, errors, ignores, import_bytes, is_partial_package
337340

338341

339342
def read_statement(state: State, data: ReadBuffer) -> Statement:

mypy/test/test_nativeparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def locs(start_line: int, start_column: int, end_line: int, end_column: int) ->
235235
]
236236

237237
with temp_source("print('hello')") as fnam:
238-
b, _, _, _ = parse_to_binary_ast(fnam, Options())
238+
b, _, _, _, _ = parse_to_binary_ast(fnam, Options())
239239
assert list(b) == (
240240
[LITERAL_INT, 22, nodes.EXPR_STMT, nodes.CALL_EXPR]
241241
+ [nodes.NAME_EXPR, LITERAL_STR]

0 commit comments

Comments
 (0)