3636 from ..interpreterbase import FeatureCheckBase , SubProject , TYPE_var , TYPE_kwargs , TYPE_nvar , TYPE_nkwargs
3737 from .interpreter import Interpreter
3838
39- from typing_extensions import TypedDict
39+ from typing_extensions import Literal , TypedDict
4040
4141 class EnvironmentSeparatorKW (TypedDict ):
4242
@@ -52,18 +52,36 @@ class InternalDependencyAsKW(TypedDict):
5252def extract_required_kwarg (kwargs : 'kwargs.ExtractRequired' ,
5353 subproject : 'SubProject' ,
5454 feature_check : T .Optional [FeatureCheckBase ] = None ,
55- default : bool = True ) -> T .Tuple [bool , bool , T .Optional [str ]]:
55+ default : bool = True
56+ ) -> T .Union [T .Tuple [Literal [True ], bool , str ],
57+ T .Tuple [Literal [False ], bool , None ]]:
58+ """Check common keyword arguments for required status.
59+
60+ This handles booleans vs feature option.
61+
62+ :param kwargs:
63+ keyword arguments from the Interpreter, containing a `required` argument
64+ :param subproject: The subproject this is
65+ :param feature_check:
66+ A custom feature check for this use of `required` with a
67+ `UserFeatureOption`, defaults to None.
68+ :param default:
69+ The default value is `required` is not set in `kwargs`, defaults to
70+ True
71+ :raises InterpreterException: If the type of `kwargs['required']` is invalid
72+ :return:
73+ a tuple of `disabled, required, feature_name`. If `disabled` is `True`
74+ `feature_name` will be a string, otherwise it is `None`
75+ """
5676 val = kwargs .get ('required' , default )
57- disabled = False
5877 required = False
59- feature : T .Optional [str ] = None
6078 if isinstance (val , options .UserFeatureOption ):
6179 if not feature_check :
6280 feature_check = FeatureNew ('User option "feature"' , '0.47.0' )
6381 feature_check .use (subproject )
6482 feature = val .name
6583 if val .is_disabled ():
66- disabled = True
84+ return True , required , feature
6785 elif val .is_enabled ():
6886 required = True
6987 elif isinstance (val , bool ):
@@ -76,7 +94,7 @@ def extract_required_kwarg(kwargs: 'kwargs.ExtractRequired',
7694 # TODO: this should be removed, and those callers should learn about FeatureOptions
7795 kwargs ['required' ] = required
7896
79- return disabled , required , feature
97+ return False , required , None
8098
8199def extract_search_dirs (kwargs : 'kwargs.ExtractSearchDirs' ) -> T .List [str ]:
82100 search_dirs_str = mesonlib .stringlistify (kwargs .get ('dirs' , []))
0 commit comments