Skip to content

Commit 33c6ad5

Browse files
zkneupperZachary Kneupperpre-commit-ci[bot]
authored
Replace some for loops, and other minor changes (#8660)
* Replace for loop using the operator * Replace for loop with a generator expression inside any() * Replace for loop with a dictionary comprehension * Use list comprehension * Simplify arguments for range() * Change newfuncargs variable to in-line dictionary comprehension * is_ancestor: return base.is_relative_to(query) * Remove unneeded import of pathlib * Try using PurePath * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Import PurePath on new line * Revert and remove is_relative_to Co-authored-by: Zachary Kneupper <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 364bbe4 commit 33c6ad5

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

src/_pytest/doctest.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,7 @@ def _is_doctest(config: Config, path: Path, parent: Collector) -> bool:
145145
if path.suffix in (".txt", ".rst") and parent.session.isinitpath(path):
146146
return True
147147
globs = config.getoption("doctestglob") or ["test*.txt"]
148-
for glob in globs:
149-
if fnmatch_ex(glob, path):
150-
return True
151-
return False
148+
return any(fnmatch_ex(glob, path) for glob in globs)
152149

153150

154151
class ReprFailDoctest(TerminalRepr):

src/_pytest/fixtures.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def get_parametrized_fixture_keys(item: nodes.Item, scopenum: int) -> Iterator[_
276276
def reorder_items(items: Sequence[nodes.Item]) -> List[nodes.Item]:
277277
argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]] = {}
278278
items_by_argkey: Dict[int, Dict[_Key, Deque[nodes.Item]]] = {}
279-
for scopenum in range(0, scopenum_function):
279+
for scopenum in range(scopenum_function):
280280
d: Dict[nodes.Item, Dict[_Key, None]] = {}
281281
argkeys_cache[scopenum] = d
282282
item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque)
@@ -296,7 +296,7 @@ def fix_cache_order(
296296
argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]],
297297
items_by_argkey: Dict[int, Dict[_Key, "Deque[nodes.Item]"]],
298298
) -> None:
299-
for scopenum in range(0, scopenum_function):
299+
for scopenum in range(scopenum_function):
300300
for key in argkeys_cache[scopenum].get(item, []):
301301
items_by_argkey[scopenum][key].appendleft(item)
302302

@@ -377,10 +377,7 @@ def _fill_fixtures_impl(function: "Function") -> None:
377377
fm.session._setupstate.setup(function)
378378
request._fillfixtures()
379379
# Prune out funcargs for jstests.
380-
newfuncargs = {}
381-
for name in fi.argnames:
382-
newfuncargs[name] = function.funcargs[name]
383-
function.funcargs = newfuncargs
380+
function.funcargs = {name: function.funcargs[name] for name in fi.argnames}
384381
else:
385382
request._fillfixtures()
386383

src/_pytest/main.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,10 +241,7 @@ def is_ancestor(base: Path, query: Path) -> bool:
241241
"""Return whether query is an ancestor of base."""
242242
if base == query:
243243
return True
244-
for parent in base.parents:
245-
if parent == query:
246-
return True
247-
return False
244+
return query in base.parents
248245

249246
# check if path is an ancestor of cwd
250247
if is_ancestor(Path.cwd(), Path(path).absolute()):

src/_pytest/python_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ def _check_type(self) -> None:
130130

131131
def _recursive_list_map(f, x):
132132
if isinstance(x, list):
133-
return list(_recursive_list_map(f, xi) for xi in x)
133+
return [_recursive_list_map(f, xi) for xi in x]
134134
else:
135135
return f(x)
136136

0 commit comments

Comments
 (0)