dependencies/base: Make MissingCompiler inherit Compiler for mypy

This allows mypy and pyright to correctly determine the return types
from methods, but makes 0 changes at runtime.
pull/12579/head
Dylan Baker 1 year ago
parent 8c70ce466b
commit 52638e8c65
  1. 21
      mesonbuild/dependencies/base.py

@ -39,15 +39,34 @@ if T.TYPE_CHECKING:
)
from ..interpreter.type_checking import PkgConfigDefineType
_MissingCompilerBase = Compiler
else:
_MissingCompilerBase = object
class DependencyException(MesonException):
'''Exceptions raised while trying to find dependencies'''
class MissingCompiler:
class MissingCompiler(_MissingCompilerBase):
"""Represent a None Compiler - when no tool chain is found.
replacing AttributeError with DependencyException"""
# These are needed in type checking mode to avoid errors, but we don't want
# the extra overhead at runtime
if T.TYPE_CHECKING:
def __init__(self) -> None:
pass
def get_optimization_args(self, optimization_level: str) -> T.List[str]:
return []
def get_output_args(self, outputname: str) -> T.List[str]:
return []
def sanity_check(self, work_dir: str, environment: 'Environment') -> None:
return None
def __getattr__(self, item: str) -> T.Any:
if item.startswith('__'):
raise AttributeError()

Loading…
Cancel
Save