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):
 | 
					    if path.suffix in (".txt", ".rst") and parent.session.isinitpath(path):
 | 
				
			||||||
        return True
 | 
					        return True
 | 
				
			||||||
    globs = config.getoption("doctestglob") or ["test*.txt"]
 | 
					    globs = config.getoption("doctestglob") or ["test*.txt"]
 | 
				
			||||||
    for glob in globs:
 | 
					    return any(fnmatch_ex(glob, path) for glob in globs)
 | 
				
			||||||
        if fnmatch_ex(glob, path):
 | 
					 | 
				
			||||||
            return True
 | 
					 | 
				
			||||||
    return False
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class ReprFailDoctest(TerminalRepr):
 | 
					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]:
 | 
					def reorder_items(items: Sequence[nodes.Item]) -> List[nodes.Item]:
 | 
				
			||||||
    argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]] = {}
 | 
					    argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]] = {}
 | 
				
			||||||
    items_by_argkey: Dict[int, Dict[_Key, Deque[nodes.Item]]] = {}
 | 
					    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]] = {}
 | 
					        d: Dict[nodes.Item, Dict[_Key, None]] = {}
 | 
				
			||||||
        argkeys_cache[scopenum] = d
 | 
					        argkeys_cache[scopenum] = d
 | 
				
			||||||
        item_d: Dict[_Key, Deque[nodes.Item]] = defaultdict(deque)
 | 
					        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]]],
 | 
					    argkeys_cache: Dict[int, Dict[nodes.Item, Dict[_Key, None]]],
 | 
				
			||||||
    items_by_argkey: Dict[int, Dict[_Key, "Deque[nodes.Item]"]],
 | 
					    items_by_argkey: Dict[int, Dict[_Key, "Deque[nodes.Item]"]],
 | 
				
			||||||
) -> None:
 | 
					) -> None:
 | 
				
			||||||
    for scopenum in range(0, scopenum_function):
 | 
					    for scopenum in range(scopenum_function):
 | 
				
			||||||
        for key in argkeys_cache[scopenum].get(item, []):
 | 
					        for key in argkeys_cache[scopenum].get(item, []):
 | 
				
			||||||
            items_by_argkey[scopenum][key].appendleft(item)
 | 
					            items_by_argkey[scopenum][key].appendleft(item)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -377,10 +377,7 @@ def _fill_fixtures_impl(function: "Function") -> None:
 | 
				
			||||||
        fm.session._setupstate.setup(function)
 | 
					        fm.session._setupstate.setup(function)
 | 
				
			||||||
        request._fillfixtures()
 | 
					        request._fillfixtures()
 | 
				
			||||||
        # Prune out funcargs for jstests.
 | 
					        # Prune out funcargs for jstests.
 | 
				
			||||||
        newfuncargs = {}
 | 
					        function.funcargs = {name: function.funcargs[name] for name in fi.argnames}
 | 
				
			||||||
        for name in fi.argnames:
 | 
					 | 
				
			||||||
            newfuncargs[name] = function.funcargs[name]
 | 
					 | 
				
			||||||
        function.funcargs = newfuncargs
 | 
					 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        request._fillfixtures()
 | 
					        request._fillfixtures()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -241,10 +241,7 @@ def validate_basetemp(path: str) -> str:
 | 
				
			||||||
        """Return whether query is an ancestor of base."""
 | 
					        """Return whether query is an ancestor of base."""
 | 
				
			||||||
        if base == query:
 | 
					        if base == query:
 | 
				
			||||||
            return True
 | 
					            return True
 | 
				
			||||||
        for parent in base.parents:
 | 
					        return query in base.parents
 | 
				
			||||||
            if parent == query:
 | 
					 | 
				
			||||||
                return True
 | 
					 | 
				
			||||||
        return False
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    # check if path is an ancestor of cwd
 | 
					    # check if path is an ancestor of cwd
 | 
				
			||||||
    if is_ancestor(Path.cwd(), Path(path).absolute()):
 | 
					    if is_ancestor(Path.cwd(), Path(path).absolute()):
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -130,7 +130,7 @@ class ApproxBase:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def _recursive_list_map(f, x):
 | 
					def _recursive_list_map(f, x):
 | 
				
			||||||
    if isinstance(x, list):
 | 
					    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:
 | 
					    else:
 | 
				
			||||||
        return f(x)
 | 
					        return f(x)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue