aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/backends.py
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/backend/backends.py
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/backend/backends.py')
-rw-r--r--mesonbuild/backend/backends.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/mesonbuild/backend/backends.py b/mesonbuild/backend/backends.py
index 1e5a13e..484e4cc 100644
--- a/mesonbuild/backend/backends.py
+++ b/mesonbuild/backend/backends.py
@@ -36,6 +36,7 @@ from ..mesonlib import (
)
if T.TYPE_CHECKING:
+ from .._typing import ImmutableListProtocol
from ..arglist import CompilerArgs
from ..compilers import Compiler
from ..interpreter import Interpreter, Test
@@ -1103,21 +1104,20 @@ class Backend:
return result
@lru_cache(maxsize=None)
- def get_custom_target_provided_by_generated_source(self, generated_source):
- libs = []
+ def get_custom_target_provided_by_generated_source(self, generated_source: build.CustomTarget) -> 'ImmutableListProtocol[str]':
+ libs: T.List[str] = []
for f in generated_source.get_outputs():
if self.environment.is_library(f):
libs.append(os.path.join(self.get_target_dir(generated_source), f))
return libs
@lru_cache(maxsize=None)
- def get_custom_target_provided_libraries(self, target):
- libs = []
+ def get_custom_target_provided_libraries(self, target: T.Union[build.BuildTarget, build.CustomTarget]) -> 'ImmutableListProtocol[str]':
+ libs: T.List[str] = []
for t in target.get_generated_sources():
if not isinstance(t, build.CustomTarget):
continue
- l = self.get_custom_target_provided_by_generated_source(t)
- libs = libs + l
+ libs.extend(self.get_custom_target_provided_by_generated_source(t))
return libs
def is_unity(self, target):