Skip to content

Commit e2a34f7

Browse files
committed
python: Use a reduce pattern in PythonBuildConfig.__getitem__()
See mesonbuild#13945 (comment) Signed-off-by: Michał Górny <[email protected]>
1 parent 69a984d commit e2a34f7

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

mesonbuild/dependencies/python.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from __future__ import annotations
55

6-
import functools, json, os, sys, textwrap
6+
import functools, json, operator, os, sys, textwrap
77
from pathlib import Path
88
import typing as T
99

@@ -101,10 +101,7 @@ def __init__(self, path: str) -> None:
101101
self._expand_paths()
102102

103103
def __getitem__(self, key: str) -> T.Any:
104-
value = self._data
105-
for part in key.split('.'):
106-
value = value[part]
107-
return value
104+
return functools.reduce(operator.getitem, key.split('.'), self._data)
108105

109106
def __contains__(self, key: str) -> bool:
110107
try:

0 commit comments

Comments
 (0)