Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed node_check for 3.8 #2321

Merged
merged 1 commit into from
Nov 8, 2023
Merged
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: 11 additions & 1 deletion backend/src/api/node_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os
import pathlib
from enum import Enum
from typing import Any, Callable, NewType, Union, cast, get_args
from typing import Any, Callable, NewType, Tuple, Union, cast, get_args

from .input import BaseInput
from .output import BaseOutput
Expand Down Expand Up @@ -70,6 +70,15 @@ def visit_BinOp(self, node: ast.BinOp): # noqa
)
return super().visit_BinOp(node)

def visit_Subscript(self, node: ast.Subscript): # noqa
if isinstance(node.value, ast.Name) and node.value.id == "tuple":
return ast.Subscript(
value=ast.Name(id="Tuple", ctx=ast.Load()),
slice=node.slice,
ctx=ast.Load(),
)
return super().visit_Subscript(node)


def compile_type_string(s: str, filename: str = "<string>"):
tree = ast.parse(s, filename, "eval")
Expand All @@ -84,6 +93,7 @@ def eval_type(t: str | _Ty, __globals: dict[str, Any]):
# `compile_type_string` adds `Union`, so we need it in scope
local_scope = {
"Union": Union,
"Tuple": Tuple,
}

try:
Expand Down