diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2022-03-01 23:12:54 -0500 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2022-03-07 19:01:04 -0500 |
commit | 187dc656f48ba7a86a14a5c8d9f16a3b2b7d8770 (patch) | |
tree | 5ed516e772e7edb4ab38c12feaf763fe030cf888 /mesonbuild/interpreterbase | |
parent | d072ebc9554e5661419d6d75285bfee24dca743f (diff) | |
download | meson-187dc656f48ba7a86a14a5c8d9f16a3b2b7d8770.zip meson-187dc656f48ba7a86a14a5c8d9f16a3b2b7d8770.tar.gz meson-187dc656f48ba7a86a14a5c8d9f16a3b2b7d8770.tar.bz2 |
merge various TYPE_CHECKING blocks into one
A bunch of files have several T.TYPE_CHECKING blocks that each do some
things which could just as well be done once, with a single `if`
statement. Make them do so.
Diffstat (limited to 'mesonbuild/interpreterbase')
-rw-r--r-- | mesonbuild/interpreterbase/baseobjects.py | 14 | ||||
-rw-r--r-- | mesonbuild/interpreterbase/decorators.py | 22 |
2 files changed, 18 insertions, 18 deletions
diff --git a/mesonbuild/interpreterbase/baseobjects.py b/mesonbuild/interpreterbase/baseobjects.py index 7186001..2e675e2 100644 --- a/mesonbuild/interpreterbase/baseobjects.py +++ b/mesonbuild/interpreterbase/baseobjects.py @@ -23,9 +23,16 @@ import typing as T from abc import ABCMeta if T.TYPE_CHECKING: + from typing_extensions import Protocol + # Object holders need the actual interpreter from ..interpreter import Interpreter + __T = T.TypeVar('__T', bound=TYPE_var, contravariant=True) + + class OperatorCall(Protocol[__T]): + def __call__(self, other: __T) -> TYPE_var: ... + TV_fw_var = T.Union[str, int, bool, list, dict, 'InterpreterObject'] TV_fw_args = T.List[T.Union[mparser.BaseNode, TV_fw_var]] TV_fw_kwargs = T.Dict[str, T.Union[mparser.BaseNode, TV_fw_var]] @@ -41,13 +48,6 @@ TYPE_key_resolver = T.Callable[[mparser.BaseNode], str] SubProject = T.NewType('SubProject', str) -if T.TYPE_CHECKING: - from typing_extensions import Protocol - __T = T.TypeVar('__T', bound=TYPE_var, contravariant=True) - - class OperatorCall(Protocol[__T]): - def __call__(self, other: __T) -> TYPE_var: ... - class InterpreterObject: def __init__(self, *, subproject: T.Optional['SubProject'] = None) -> None: self.methods: T.Dict[ diff --git a/mesonbuild/interpreterbase/decorators.py b/mesonbuild/interpreterbase/decorators.py index 7c04483..359fa85 100644 --- a/mesonbuild/interpreterbase/decorators.py +++ b/mesonbuild/interpreterbase/decorators.py @@ -25,10 +25,21 @@ import abc import itertools import copy import typing as T + if T.TYPE_CHECKING: + from typing_extensions import Protocol + from .. import mparser + from .baseobjects import InterpreterObject from .interpreterbase import SubProject + _TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True) + _TV_ARG1 = T.TypeVar('_TV_ARG1', bound=TYPE_var, contravariant=True) + + class FN_Operator(Protocol[_TV_IntegerObject, _TV_ARG1]): + def __call__(s, self: _TV_IntegerObject, other: _TV_ARG1) -> TYPE_var: ... + _TV_FN_Operator = T.TypeVar('_TV_FN_Operator', bound=FN_Operator) + def get_callee_args(wrapped_args: T.Sequence[T.Any]) -> T.Tuple['mparser.BaseNode', T.List['TYPE_var'], 'TYPE_kwargs', 'SubProject']: # First argument could be InterpreterBase, InterpreterObject or ModuleObject. # In the case of a ModuleObject it is the 2nd argument (ModuleState) that @@ -116,17 +127,6 @@ class permittedKwargs: return f(*wrapped_args, **wrapped_kwargs) return T.cast(TV_func, wrapped) -if T.TYPE_CHECKING: - from .baseobjects import InterpreterObject - from typing_extensions import Protocol - - _TV_IntegerObject = T.TypeVar('_TV_IntegerObject', bound=InterpreterObject, contravariant=True) - _TV_ARG1 = T.TypeVar('_TV_ARG1', bound=TYPE_var, contravariant=True) - - class FN_Operator(Protocol[_TV_IntegerObject, _TV_ARG1]): - def __call__(s, self: _TV_IntegerObject, other: _TV_ARG1) -> TYPE_var: ... - _TV_FN_Operator = T.TypeVar('_TV_FN_Operator', bound=FN_Operator) - def typed_operator(operator: MesonOperator, types: T.Union[T.Type, T.Tuple[T.Type, ...]]) -> T.Callable[['_TV_FN_Operator'], '_TV_FN_Operator']: """Decorator that does type checking for operator calls. |