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 <zacharykneupper@Zacharys-MBP.lan> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
364bbe42fc
commit
33c6ad5bf7
|
@ -145,10 +145,7 @@ def _is_doctest(config: Config, path: Path, parent: Collector) -> bool:
|
|||
if path.suffix in (".txt", ".rst") and parent.session.isinitpath(path):
|
||||
return True
|
||||
globs = config.getoption("doctestglob") or ["test*.txt"]
|
||||
for glob in globs:
|
||||
if fnmatch_ex(glob, path):
|
||||
return True
|
||||
return False
|
||||
return any(fnmatch_ex(glob, path) for glob in globs)
|
||||
|
||||
|
||||
class ReprFailDoctest(TerminalRepr):
|
||||
|
|
|
@ -276,7 +276,7 @@ def get_parametrized_fixture_keys(item: nodes.Item, scopenum: int) -> Iterator[_
|
|||
def reorder_items(items: Sequence[nodes.Item]) -> List[nodes.Item]:
|
||||
argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]] = {}
|
||||
items_by_argkey: Dict[int, Dict[_Key, Deque[nodes.Item]]] = {}
|
||||
for scopenum in range(0, scopenum_function):
|
||||
for scopenum in range(scopenum_function):
|
||||
d: Dict[nodes.Item, Dict[_Key, None]] = {}
|
||||
argkeys_cache[scopenum] = d
|
||||
item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque)
|
||||
|
@ -296,7 +296,7 @@ def fix_cache_order(
|
|||
argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]],
|
||||
items_by_argkey: Dict[int, Dict[_Key, "Deque[nodes.Item]"]],
|
||||
) -> None:
|
||||
for scopenum in range(0, scopenum_function):
|
||||
for scopenum in range(scopenum_function):
|
||||
for key in argkeys_cache[scopenum].get(item, []):
|
||||
items_by_argkey[scopenum][key].appendleft(item)
|
||||
|
||||
|
@ -377,10 +377,7 @@ def _fill_fixtures_impl(function: "Function") -> None:
|
|||
fm.session._setupstate.setup(function)
|
||||
request._fillfixtures()
|
||||
# Prune out funcargs for jstests.
|
||||
newfuncargs = {}
|
||||
for name in fi.argnames:
|
||||
newfuncargs[name] = function.funcargs[name]
|
||||
function.funcargs = newfuncargs
|
||||
function.funcargs = {name: function.funcargs[name] for name in fi.argnames}
|
||||
else:
|
||||
request._fillfixtures()
|
||||
|
||||
|
|
|
@ -241,10 +241,7 @@ def validate_basetemp(path: str) -> str:
|
|||
"""Return whether query is an ancestor of base."""
|
||||
if base == query:
|
||||
return True
|
||||
for parent in base.parents:
|
||||
if parent == query:
|
||||
return True
|
||||
return False
|
||||
return query in base.parents
|
||||
|
||||
# check if path is an ancestor of cwd
|
||||
if is_ancestor(Path.cwd(), Path(path).absolute()):
|
||||
|
|
|
@ -130,7 +130,7 @@ class ApproxBase:
|
|||
|
||||
def _recursive_list_map(f, x):
|
||||
if isinstance(x, list):
|
||||
return list(_recursive_list_map(f, xi) for xi in x)
|
||||
return [_recursive_list_map(f, xi) for xi in x]
|
||||
else:
|
||||
return f(x)
|
||||
|
||||
|
|
Loading…
Reference in New Issue