Renamed to ignore_bytes and reverted typevar rename

This commit is contained in:
Sebastian Mohr 2025-02-10 11:46:50 +01:00
parent 10e52c68c9
commit ebe88885c5
2 changed files with 16 additions and 13 deletions

View file

@ -210,7 +210,7 @@ def sorted_walk(
"""
# Make sure the paths aren't Unicode strings.
bytes_path = bytestring_path(path)
_ignore = [ # rename prevents mypy variable shadowing issue
ignore_bytes = [ # rename prevents mypy variable shadowing issue
bytestring_path(i) for i in ignore
]
@ -232,7 +232,7 @@ def sorted_walk(
# Skip ignored filenames.
skip = False
for pat in _ignore:
for pat in ignore_bytes:
if fnmatch.fnmatch(base, pat):
if logger:
logger.debug(
@ -259,7 +259,7 @@ def sorted_walk(
# Recurse into directories.
for base in dirs:
cur = os.path.join(bytes_path, base)
yield from sorted_walk(cur, _ignore, ignore_hidden, logger)
yield from sorted_walk(cur, ignore_bytes, ignore_hidden, logger)
def path_as_posix(path: bytes) -> bytes:

View file

@ -30,6 +30,7 @@ up a bottleneck stage by dividing its work among multiple threads.
To do so, pass an iterable of coroutines to the Pipeline constructor
in place of any single coroutine.
"""
from __future__ import annotations
import queue
@ -153,10 +154,10 @@ def multiple(messages):
return MultiMessage(messages)
# Arguments of the function (omitting the task)
Args = TypeVarTuple("Args")
# Task as an additional argument to the function
Task = TypeVar("Task")
A = TypeVarTuple("A") # Arguments of a function (omitting the task)
T = TypeVar("T") # Type of the task
# Normally these are concatenated i.e. (*args, task)
# Return type of the function (should normally be task but sadly
# we cant enforce this with the current stage functions without
# a refactor)
@ -165,7 +166,7 @@ R = TypeVar("R")
def stage(
func: Callable[
[Unpack[Args], Task],
[Unpack[A], T],
R | None,
],
):
@ -182,8 +183,8 @@ def stage(
[3, 4, 5]
"""
def coro(*args: Unpack[Args]) -> Generator[R | Task | None, Task, None]:
task: R | Task | None = None
def coro(*args: Unpack[A]) -> Generator[R | T | None, T, None]:
task: R | T | None = None
while True:
task = yield task
task = func(*(args + (task,)))
@ -191,7 +192,7 @@ def stage(
return coro
def mutator_stage(func: Callable[[Unpack[Args], Task], R]):
def mutator_stage(func: Callable[[Unpack[A], T], R]):
"""Decorate a function that manipulates items in a coroutine to
become a simple stage.
@ -206,7 +207,7 @@ def mutator_stage(func: Callable[[Unpack[Args], Task], R]):
[{'x': True}, {'a': False, 'x': True}]
"""
def coro(*args: Unpack[Args]) -> Generator[Task | None, Task, None]:
def coro(*args: Unpack[A]) -> Generator[T | None, T, None]:
task = None
while True:
task = yield task
@ -425,7 +426,9 @@ class Pipeline:
for i in range(1, queue_count):
for coro in self.stages[i]:
threads.append(
MiddlePipelineThread(coro, queues[i - 1], queues[i], threads)
MiddlePipelineThread(
coro, queues[i - 1], queues[i], threads
)
)
# Last stage.