diff options
author | Eli Schwartz <eschwartz@archlinux.org> | 2023-07-03 12:29:12 -0400 |
---|---|---|
committer | Eli Schwartz <eschwartz@archlinux.org> | 2023-07-19 18:31:37 -0400 |
commit | 621264e1d4f1a8623c6f82b774c8c9f099e98b62 (patch) | |
tree | 5a6e7b75008f66accc0fa745395cd994ac92ae3f /mesonbuild/linkers/linkers.py | |
parent | ca34c7617036d5af1559767deba36038ecac101d (diff) | |
download | meson-621264e1d4f1a8623c6f82b774c8c9f099e98b62.zip meson-621264e1d4f1a8623c6f82b774c8c9f099e98b62.tar.gz meson-621264e1d4f1a8623c6f82b774c8c9f099e98b62.tar.bz2 |
linkers: fix mypy errors that were ignored due to lack of inheritance
A linker mixin has to be able to align with the base linker it will be
used for, in order to reference super(). Since they weren't inherited,
calls to super() resulted in mypy errors, which we ignored, and casting.
Use the same trick we use for compilers, and make the linker inherit
from the base linker type when running under mypy, and from object at
runtime.
Diffstat (limited to 'mesonbuild/linkers/linkers.py')
-rw-r--r-- | mesonbuild/linkers/linkers.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/mesonbuild/linkers/linkers.py b/mesonbuild/linkers/linkers.py index 8fb3656..5e76a92 100644 --- a/mesonbuild/linkers/linkers.py +++ b/mesonbuild/linkers/linkers.py @@ -309,6 +309,13 @@ class DynamicLinker(metaclass=abc.ABCMeta): return [] +if T.TYPE_CHECKING: + StaticLinkerBase = StaticLinker + DynamicLinkerBase = DynamicLinker +else: + StaticLinkerBase = DynamicLinkerBase = object + + class VisualStudioLikeLinker: always_args = ['/NOLOGO'] @@ -1218,7 +1225,7 @@ class PGIStaticLinker(StaticLinker): NvidiaHPC_StaticLinker = PGIStaticLinker -class VisualStudioLikeLinkerMixin: +class VisualStudioLikeLinkerMixin(DynamicLinkerBase): """Mixin class for dynamic linkers that act like Microsoft's link.exe.""" @@ -1241,7 +1248,7 @@ class VisualStudioLikeLinkerMixin: prefix_arg: T.Union[str, T.List[str]], always_args: T.List[str], *, version: str = 'unknown version', direct: bool = True, machine: str = 'x86'): # There's no way I can find to make mypy understand what's going on here - super().__init__(exelist, for_machine, prefix_arg, always_args, version=version) # type: ignore + super().__init__(exelist, for_machine, prefix_arg, always_args, version=version) self.machine = machine self.direct = direct @@ -1255,8 +1262,8 @@ class VisualStudioLikeLinkerMixin: return self._apply_prefix(['/MACHINE:' + self.machine, '/OUT:' + outputname]) def get_always_args(self) -> T.List[str]: - parent = super().get_always_args() # type: ignore - return self._apply_prefix('/nologo') + T.cast('T.List[str]', parent) + parent = super().get_always_args() + return self._apply_prefix('/nologo') + parent def get_search_args(self, dirname: str) -> T.List[str]: return self._apply_prefix('/LIBPATH:' + dirname) |