summaryrefslogtreecommitdiff
path: root/mesonbuild/compilers/mixins/emscripten.py
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-21 12:48:51 -0700
committerDylan Baker <dylan@pnwbakers.com>2020-09-24 12:14:13 -0700
commit682d22129c32edc64c610478368e1bc1f1dbc921 (patch)
tree093f5e8b064772ee3f0811c81123bb0df872bfee /mesonbuild/compilers/mixins/emscripten.py
parent2c0fbe161d61d2d15d29892456544442ab1c4ff6 (diff)
downloadmeson-682d22129c32edc64c610478368e1bc1f1dbc921.tar.gz
compilers: Tell mypy that the compiler mixins are just that
We do this by making the mixins inherit the Compiler class only when mypy is examining the code (using some clever inheritance shenanigans). This caught a bunch of issues, and also lets us delete a ton of code.
Diffstat (limited to 'mesonbuild/compilers/mixins/emscripten.py')
-rw-r--r--mesonbuild/compilers/mixins/emscripten.py18
1 files changed, 9 insertions, 9 deletions
diff --git a/mesonbuild/compilers/mixins/emscripten.py b/mesonbuild/compilers/mixins/emscripten.py
index f15db40bf..87bc40c87 100644
--- a/mesonbuild/compilers/mixins/emscripten.py
+++ b/mesonbuild/compilers/mixins/emscripten.py
@@ -20,15 +20,17 @@ import typing as T
from ... import coredata
if T.TYPE_CHECKING:
- from ...envconfig import MachineChoice
from ...environment import Environment
+ from ...compilers.compilers import Compiler
+else:
+ # This is a bit clever, for mypy we pretend that these mixins descend from
+ # Compiler, so we get all of the methods and attributes defined for us, but
+ # for runtime we make them descend from object (which all classes normally
+ # do). This gives up DRYer type checking, with no runtime impact
+ Compiler = object
-class EmscriptenMixin:
-
- if T.TYPE_CHECKING:
- for_machine = MachineChoice.HOST
- language = ''
+class EmscriptenMixin(Compiler):
def _get_compile_output(self, dirname: str, mode: str) -> str:
# In pre-processor mode, the output is sent to stdout and discarded
@@ -54,9 +56,7 @@ class EmscriptenMixin:
return args
def get_options(self) -> 'coredata.OptionDictType':
- # Mypy and co-operative inheritance
- _opts = super().get_options() # type: ignore
- opts = T.cast('coredata.OptionDictType', _opts)
+ opts = super().get_options()
opts.update({
'{}_thread_count'.format(self.language): coredata.UserIntegerOption(
'Number of threads to use in web assembly, set to 0 to disable',