fix(lab): avoid runtime typing on Python 3.9
This commit is contained in:
@@ -41,7 +41,7 @@ def test_component_image_installer_binds_bases_and_adapter_sources() -> None:
|
||||
for digest in (
|
||||
"58df7489c3f2276f9591d500a012dee03e23d35543ce3c390b4c001e6bf90794",
|
||||
"591cb382c099eeb05e7ec16e2371e0b2da54d2bb5c49ec0f4ac88dbf72b0f0cd",
|
||||
"91c1878a58acf3ac35ce894f4de9b63cba3b7f29a65548e28df176063a2953c9",
|
||||
"b7dcb3532a65ddc2d6988391056dd2f58f5f631a4db978ebfb5e170bde9c3916",
|
||||
"b48ef255403abcfd177a6550688410a52b0fbd29d2a54c8417cb5a0daa330ad5",
|
||||
"a398a43fe4069bf1b1fc2ec61b44df53dad6072cccb6d10a2627e76a96a94056",
|
||||
):
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import hashlib
|
||||
import json
|
||||
import shutil
|
||||
@@ -35,6 +36,20 @@ def test_component_entrypoints_keep_the_legacy_python39_syntax_floor() -> None:
|
||||
for path in paths:
|
||||
source = path.read_text(encoding="utf-8")
|
||||
assert "\ntype " not in source
|
||||
module = ast.parse(source, filename=str(path), feature_version=(3, 9))
|
||||
for statement in module.body:
|
||||
if isinstance(statement, ast.Assign):
|
||||
assert not any(
|
||||
isinstance(node, ast.BinOp) and isinstance(node.op, ast.BitOr)
|
||||
for node in ast.walk(statement.value)
|
||||
), f"runtime-evaluated PEP 604 alias in {path.name}"
|
||||
for call in (node for node in ast.walk(module) if isinstance(node, ast.Call)):
|
||||
if isinstance(call.func, ast.Name) and call.func.id == "cast":
|
||||
assert call.args
|
||||
assert not any(
|
||||
isinstance(node, ast.BinOp) and isinstance(node.op, ast.BitOr)
|
||||
for node in ast.walk(call.args[0])
|
||||
), f"runtime-evaluated PEP 604 cast in {path.name}"
|
||||
assert "slots=True" not in paths[0].read_text(encoding="utf-8")
|
||||
assert "slots=True" not in paths[2].read_text(encoding="utf-8")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user