aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/cmake
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2020-09-24 09:53:41 -0700
committerDylan Baker <dylan@pnwbakers.com>2021-06-02 15:53:17 -0700
commit113a1595149b72ee0a572ed215db616c5a6d8a20 (patch)
tree2ef6d92f919aaea3fb83b06631b38ebbe56aa9ce /mesonbuild/cmake
parentf8be4f8fc747772d9639fdbb6e84ddbcfb61593a (diff)
downloadmeson-113a1595149b72ee0a572ed215db616c5a6d8a20.zip
meson-113a1595149b72ee0a572ed215db616c5a6d8a20.tar.gz
meson-113a1595149b72ee0a572ed215db616c5a6d8a20.tar.bz2
use an immutable list for an lru_cached functions
When mutable items are stored in an lru cache, changing the returned items changes the cached items as well. Therefore we want to ensure that we're not mutating them. Using the ImmutableListProtocol allows mypy to find mutations and reject them. This doesn't solve the problem of mutable values inside the values, so you could have to do things like: ```python ImmutableListProtocol[ImmutableListProtocol[str]] ``` or equally hacky. It can also be used for input types and acts a bit like C's const: ```python def foo(arg: ImmutableListProtocol[str]) -> T.List[str]: arg[1] = 'foo' # works while running, but mypy errors ```
Diffstat (limited to 'mesonbuild/cmake')
-rw-r--r--mesonbuild/cmake/interpreter.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index cc6adf1..f79f7d2 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -51,6 +51,7 @@ from ..mparser import (
if T.TYPE_CHECKING:
+ from .._typing import ImmutableListProtocol
from ..build import Build
from ..backend.backends import Backend
from ..environment import Environment
@@ -582,14 +583,14 @@ class ConverterTarget:
self.compile_opts[lang] += [x for x in opts if x not in self.compile_opts[lang]]
@lru_cache(maxsize=None)
- def _all_source_suffixes(self) -> T.List[str]:
+ def _all_source_suffixes(self) -> 'ImmutableListProtocol[str]':
suffixes = [] # type: T.List[str]
for exts in lang_suffixes.values():
suffixes += [x for x in exts]
return suffixes
@lru_cache(maxsize=None)
- def _all_lang_stds(self, lang: str) -> T.List[str]:
+ def _all_lang_stds(self, lang: str) -> 'ImmutableListProtocol[str]':
try:
res = self.env.coredata.options[OptionKey('std', machine=MachineChoice.BUILD, lang=lang)].choices
except KeyError: