From f83dca32fe340727ada08b46d70bfc6dbba52d84 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 4 Sep 2024 09:39:38 -0700 Subject: [PATCH] interpreterbase: Use explicit `TypeAlias` annotation to allow recursive types And fix all of the issues that pop up once we remove the use of `Any`, which hides so many problems. --- mesonbuild/interpreterbase/baseobjects.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mesonbuild/interpreterbase/baseobjects.py b/mesonbuild/interpreterbase/baseobjects.py index 9a119a98a..a5ccccedc 100644 --- a/mesonbuild/interpreterbase/baseobjects.py +++ b/mesonbuild/interpreterbase/baseobjects.py @@ -15,7 +15,7 @@ from abc import ABCMeta from contextlib import AbstractContextManager if T.TYPE_CHECKING: - from typing_extensions import Protocol + from typing_extensions import Protocol, TypeAlias # Object holders need the actual interpreter from ..interpreter import Interpreter @@ -28,8 +28,8 @@ if T.TYPE_CHECKING: TV_func = T.TypeVar('TV_func', bound=T.Callable[..., T.Any]) -TYPE_elementary = T.Union[str, int, bool, T.List[T.Any], T.Dict[str, T.Any]] -TYPE_var = T.Union[TYPE_elementary, HoldableObject, 'MesonInterpreterObject'] +TYPE_elementary: TypeAlias = T.Union[str, int, bool, T.Sequence['TYPE_elementary'], T.Dict[str, 'TYPE_elementary']] +TYPE_var: TypeAlias = T.Union[TYPE_elementary, HoldableObject, 'MesonInterpreterObject', T.Sequence['TYPE_var'], T.Dict[str, 'TYPE_var']] TYPE_nvar = T.Union[TYPE_var, mparser.BaseNode] TYPE_kwargs = T.Dict[str, TYPE_var] TYPE_nkwargs = T.Dict[str, TYPE_nvar] @@ -122,7 +122,7 @@ class MutableInterpreterObject: ''' Dummy class to mark the object type as mutable ''' HoldableTypes = (HoldableObject, int, bool, str, list, dict) -TYPE_HoldableTypes = T.Union[TYPE_elementary, HoldableObject] +TYPE_HoldableTypes = T.Union[TYPE_var, HoldableObject] InterpreterObjectTypeVar = T.TypeVar('InterpreterObjectTypeVar', bound=TYPE_HoldableTypes) class ObjectHolder(InterpreterObject, T.Generic[InterpreterObjectTypeVar]):