diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-03-07 15:05:37 -0800 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2023-10-16 13:28:32 -0700 |
commit | b2f681c92a3efb0bb77cf75ba5146c13cf54b2b5 (patch) | |
tree | 20ecc21d2540999b8ad0cffe12806932e370a398 /mesonbuild/build.py | |
parent | 7c101413d026ee50d950db1c5fcff48c20c757da (diff) | |
download | meson-b2f681c92a3efb0bb77cf75ba5146c13cf54b2b5.zip meson-b2f681c92a3efb0bb77cf75ba5146c13cf54b2b5.tar.gz meson-b2f681c92a3efb0bb77cf75ba5146c13cf54b2b5.tar.bz2 |
build: use a TypedDict for d_features
This allows for better type checking.
Diffstat (limited to 'mesonbuild/build.py')
-rw-r--r-- | mesonbuild/build.py | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 0f6f8e3..8185ef4 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -44,7 +44,7 @@ from .compilers import ( from .interpreterbase import FeatureNew, FeatureDeprecated if T.TYPE_CHECKING: - from typing_extensions import Literal + from typing_extensions import Literal, TypedDict from . import environment from ._typing import ImmutableListProtocol @@ -64,6 +64,13 @@ if T.TYPE_CHECKING: BuildTargetTypes = T.Union['BuildTarget', 'CustomTarget', 'CustomTargetIndex'] ObjectTypes = T.Union[str, 'File', 'ExtractedObjects', 'GeneratedTypes'] + class DFeatures(TypedDict): + + unittest: bool + debug: T.List[T.Union[str, int]] + import_dirs: T.List[IncludeDirs] + versions: T.List[T.Union[str, int]] + pch_kwargs = {'c_pch', 'cpp_pch'} lang_arg_kwargs = {f'{lang}_args' for lang in all_languages} @@ -751,7 +758,12 @@ class BuildTarget(Target): self.sources: T.List[File] = [] self.generated: T.List['GeneratedTypes'] = [] self.extra_files: T.List[File] = [] - self.d_features = defaultdict(list) + self.d_features: DFeatures = { + 'debug': kwargs.get('d_debug', []), + 'import_dirs': kwargs.get('d_import_dirs', []), + 'versions': kwargs.get('d_module_versions', []), + 'unittest': kwargs.get('d_unittest', False), + } self.pic = False self.pie = False # Track build_rpath entries so we can remove them at install time @@ -1114,21 +1126,6 @@ class BuildTarget(Target): self.vala_vapi = kwargs.get('vala_vapi', self.name + '.vapi') self.vala_gir = kwargs.get('vala_gir', None) - dfeatures = defaultdict(list) - dfeature_unittest = kwargs.get('d_unittest', False) - if dfeature_unittest: - dfeatures['unittest'] = dfeature_unittest - dfeature_versions = kwargs.get('d_module_versions', []) - if dfeature_versions: - dfeatures['versions'] = dfeature_versions - dfeature_debug = kwargs.get('d_debug', []) - if dfeature_debug: - dfeatures['debug'] = dfeature_debug - if kwargs.get('d_import_dirs') is not None: - dfeatures['import_dirs'] = kwargs['d_import_dirs'] - if dfeatures: - self.d_features = dfeatures - self.link_args = extract_as_list(kwargs, 'link_args') for i in self.link_args: if not isinstance(i, str): |