From 06d12064d0ccb1477fadf1d62492a493fb2fb947 Mon Sep 17 00:00:00 2001 From: Xavier Claessens Date: Tue, 12 Oct 2021 21:45:24 -0400 Subject: OptionOverrideProxy: Make it immutable to avoid copies It is always used as an immutable view so there is no point in doing copies. However, mypy insist it must implement the same APIs as Dict[OptionKey, UserOption[Any]] so keep faking it. --- mesonbuild/compilers/cpp.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'mesonbuild/compilers/cpp.py') diff --git a/mesonbuild/compilers/cpp.py b/mesonbuild/compilers/cpp.py index e6410c850..fe09b6b60 100644 --- a/mesonbuild/compilers/cpp.py +++ b/mesonbuild/compilers/cpp.py @@ -41,7 +41,7 @@ from .mixins.pgi import PGICompiler from .mixins.emscripten import EmscriptenMixin if T.TYPE_CHECKING: - from ..coredata import KeyedOptionDictType + from ..coredata import MutableKeyedOptionDictType, KeyedOptionDictType from ..dependencies import Dependency from ..envconfig import MachineInfo from ..environment import Environment @@ -168,7 +168,7 @@ class CPPCompiler(CLikeCompiler, Compiler): raise MesonException(f'C++ Compiler does not support -std={cpp_std}') - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = super().get_options() key = OptionKey('std', machine=self.for_machine, lang=self.language) opts.update({ @@ -196,7 +196,7 @@ class ClangCPPCompiler(ClangCompiler, CPPCompiler): '2': default_warn_args + ['-Wextra'], '3': default_warn_args + ['-Wextra', '-Wpedantic']} - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('key', machine=self.for_machine, lang=self.language) opts.update({ @@ -316,7 +316,7 @@ class ArmclangCPPCompiler(ArmclangCompiler, CPPCompiler): '2': default_warn_args + ['-Wextra'], '3': default_warn_args + ['-Wextra', '-Wpedantic']} - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('std', machine=self.for_machine, lang=self.language) opts.update({ @@ -362,7 +362,7 @@ class GnuCPPCompiler(GnuCompiler, CPPCompiler): '2': default_warn_args + ['-Wextra'], '3': default_warn_args + ['-Wextra', '-Wpedantic']} - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': key = OptionKey('std', machine=self.for_machine, lang=self.language) opts = CPPCompiler.get_options(self) opts.update({ @@ -465,7 +465,7 @@ class ElbrusCPPCompiler(ElbrusCompiler, CPPCompiler): info, exe_wrapper, linker=linker, full_version=full_version) ElbrusCompiler.__init__(self) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) cpp_stds = ['none', 'c++98', 'gnu++98'] @@ -542,7 +542,7 @@ class IntelCPPCompiler(IntelGnuLikeCompiler, CPPCompiler): '2': default_warn_args + ['-Wextra'], '3': default_warn_args + ['-Wextra']} - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) # Every Unix compiler under the sun seems to accept -std=c++03, # with the exception of ICC. Instead of preventing the user from @@ -618,7 +618,7 @@ class VisualStudioLikeCPPCompilerMixin(CompilerMixinBase): key = OptionKey('winlibs', machine=self.for_machine, lang=self.language) return T.cast('T.List[str]', options[key].value[:]) - def _get_options_impl(self, opts: 'KeyedOptionDictType', cpp_stds: T.List[str]) -> 'KeyedOptionDictType': + def _get_options_impl(self, opts: 'MutableKeyedOptionDictType', cpp_stds: T.List[str]) -> 'MutableKeyedOptionDictType': key = OptionKey('std', machine=self.for_machine, lang=self.language) opts.update({ key.evolve('eh'): coredata.UserComboOption( @@ -705,7 +705,7 @@ class VisualStudioCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixi info, exe_wrapper, linker=linker, full_version=full_version) MSVCCompiler.__init__(self, target) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': cpp_stds = ['none', 'c++11', 'vc++11'] # Visual Studio 2015 and later if version_compare(self.version, '>=19'): @@ -747,7 +747,7 @@ class ClangClCPPCompiler(CPP11AsCPP14Mixin, VisualStudioLikeCPPCompilerMixin, Cl info, exe_wrapper, linker=linker, full_version=full_version) ClangClCompiler.__init__(self, target) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest'] return self._get_options_impl(super().get_options(), cpp_stds) @@ -763,7 +763,7 @@ class IntelClCPPCompiler(VisualStudioLikeCPPCompilerMixin, IntelVisualStudioLike info, exe_wrapper, linker=linker, full_version=full_version) IntelVisualStudioLikeCompiler.__init__(self, target) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': # This has only been tested with version 19.0, cpp_stds = ['none', 'c++11', 'vc++11', 'c++14', 'vc++14', 'c++17', 'vc++17', 'c++latest'] return self._get_options_impl(super().get_options(), cpp_stds) @@ -782,7 +782,7 @@ class ArmCPPCompiler(ArmCompiler, CPPCompiler): info, exe_wrapper, linker=linker, full_version=full_version) ArmCompiler.__init__(self) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('std', machine=self.for_machine, lang=self.language) opts[key].choices = ['none', 'c++03', 'c++11'] @@ -842,7 +842,7 @@ class TICPPCompiler(TICompiler, CPPCompiler): info, exe_wrapper, linker=linker, full_version=full_version) TICompiler.__init__(self) - def get_options(self) -> 'KeyedOptionDictType': + def get_options(self) -> 'MutableKeyedOptionDictType': opts = CPPCompiler.get_options(self) key = OptionKey('std', machine=self.for_machine, lang=self.language) opts[key].choices = ['none', 'c++03'] -- cgit v1.2.1