Skip to content

Commit 1c0cfc3

Browse files
eli-schwartznirbheek
authored andcommitted
typing: simplify type annotations for libraries
In a bunch of places we need to list various types of libraries including custom_target outputs, and it gets very long. Use a common T.Union for this.
1 parent 4d510f0 commit 1c0cfc3

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

mesonbuild/build.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
from .mparser import BaseNode
5757

5858
GeneratedTypes = T.Union['CustomTarget', 'CustomTargetIndex', 'GeneratedList']
59+
LibTypes = T.Union['SharedLibrary', 'StaticLibrary', 'CustomTarget', 'CustomTargetIndex']
5960

6061
pch_kwargs = {'c_pch', 'cpp_pch'}
6162

@@ -754,7 +755,7 @@ def __init__(self, name: str, subdir: str, subproject: SubProject, for_machine:
754755
self.external_deps: T.List[dependencies.Dependency] = []
755756
self.include_dirs: T.List['IncludeDirs'] = []
756757
self.link_language = kwargs.get('link_language')
757-
self.link_targets: T.List[T.Union[SharedLibrary, StaticLibrary, 'CustomTarget', 'CustomTargetIndex']] = []
758+
self.link_targets: T.List[LibTypes] = []
758759
self.link_whole_targets: T.List[T.Union[StaticLibrary, CustomTarget, CustomTargetIndex]] = []
759760
self.link_depends = []
760761
self.added_deps = set()

mesonbuild/dependencies/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
from ..environment import Environment
3737
from ..interpreterbase import FeatureCheckBase
3838
from ..build import (
39-
CustomTarget, IncludeDirs, CustomTargetIndex, SharedLibrary,
39+
CustomTarget, IncludeDirs, CustomTargetIndex, LibTypes,
4040
StaticLibrary
4141
)
4242
from ..mesonlib import FileOrString
@@ -235,7 +235,7 @@ def generate_system_dependency(self, include_type: str) -> 'Dependency':
235235
class InternalDependency(Dependency):
236236
def __init__(self, version: str, incdirs: T.List['IncludeDirs'], compile_args: T.List[str],
237237
link_args: T.List[str],
238-
libraries: T.List[T.Union[SharedLibrary, StaticLibrary, CustomTarget, CustomTargetIndex]],
238+
libraries: T.List[LibTypes],
239239
whole_libraries: T.List[T.Union[StaticLibrary, CustomTarget, CustomTargetIndex]],
240240
sources: T.Sequence[T.Union[FileOrString, CustomTarget, StructuredSources]],
241241
ext_deps: T.List[Dependency], variables: T.Dict[str, str],

mesonbuild/modules/gnome.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2054,8 +2054,8 @@ def _generate_deps(self, state: 'ModuleState', library: str, packages: T.List[st
20542054
ofile.write(package + '\n')
20552055
return build.Data([mesonlib.File(True, outdir, fname)], install_dir, install_dir, mesonlib.FileMode(), state.subproject)
20562056

2057-
def _get_vapi_link_with(self, target: build.CustomTarget) -> T.List[T.Union[build.CustomTarget, build.CustomTargetIndex, build.SharedLibrary, build.StaticLibrary]]:
2058-
link_with: T.List[T.Union[build.StaticLibrary, build.SharedLibrary, build.CustomTarget, build.CustomTargetIndex]] = []
2057+
def _get_vapi_link_with(self, target: build.CustomTarget) -> T.List[build.LibTypes]:
2058+
link_with: T.List[build.LibTypes] = []
20592059
for dep in target.get_target_dependencies():
20602060
if isinstance(dep, build.SharedLibrary):
20612061
link_with.append(dep)
@@ -2095,7 +2095,7 @@ def generate_vapi(self, state: 'ModuleState', args: T.Tuple[str], kwargs: 'Gener
20952095

20962096
inputs = kwargs['sources']
20972097

2098-
link_with: T.List[T.Union[build.SharedLibrary, build.StaticLibrary, build.CustomTarget, build.CustomTargetIndex]] = []
2098+
link_with: T.List[build.LibTypes] = []
20992099
for i in inputs:
21002100
if isinstance(i, str):
21012101
cmd.append(os.path.join(source_dir, i))

0 commit comments

Comments
 (0)