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.
pull/13658/head
Dylan Baker 3 months ago committed by Eli Schwartz
parent 58c6b13c4e
commit f83dca32fe
  1. 8
      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]):

Loading…
Cancel
Save