Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: remove confusing app workers alias #4515

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/textual/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ async def _gather_commands(self, search_value: str) -> None:

def _cancel_gather_commands(self) -> None:
"""Cancel any operation that is gather commands."""
self.workers.cancel_group(self, self._GATHER_COMMANDS_GROUP)
self.app.workers.cancel_group(self, self._GATHER_COMMANDS_GROUP)

@on(Input.Changed)
def _input(self, event: Input.Changed) -> None:
Expand Down
10 changes: 2 additions & 8 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
from ._context import NoActiveAppError, active_message_pump
from ._node_list import NodeList
from ._types import WatchCallbackType
from ._worker_manager import WorkerManager
from .binding import Binding, BindingType, _Bindings
from .color import BLACK, WHITE, Color
from .css._error_tools import friendly_list
Expand Down Expand Up @@ -386,11 +385,6 @@ def auto_refresh(self, interval: float | None) -> None:
)
self._auto_refresh = interval

@property
def workers(self) -> WorkerManager:
"""The app's worker manager. Shortcut for `self.app.workers`."""
return self.app.workers

def run_worker(
self,
work: WorkType[ResultType],
Expand Down Expand Up @@ -423,9 +417,9 @@ def run_worker(
# If we're running a worker from inside a secondary thread,
# do so in a thread-safe way.
if self.app._thread_id != threading.get_ident():
creator = partial(self.app.call_from_thread, self.workers._new_worker)
creator = partial(self.app.call_from_thread, self.app.workers._new_worker)
else:
creator = self.workers._new_worker
creator = self.app.workers._new_worker
worker: Worker[ResultType] = creator(
work,
self,
Expand Down
2 changes: 1 addition & 1 deletion src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -3762,7 +3762,7 @@ def _on_scroll_to_region(self, message: messages.ScrollToRegion) -> None:
self.scroll_to_region(message.region, animate=True)

def _on_unmount(self) -> None:
self.workers.cancel_node(self)
self.app.workers.cancel_node(self)

def action_scroll_home(self) -> None:
if not self._allow_scroll:
Expand Down
4 changes: 2 additions & 2 deletions tests/command_palette/test_run_on_select.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async def test_with_run_on_select_on() -> None:
assert isinstance(pilot.app, CommandPaletteRunOnSelectApp)
pilot.app.action_command_palette()
await pilot.press("0")
await pilot.app.screen.workers.wait_for_complete()
await pilot.app.workers.wait_for_complete()
await pilot.press("down")
await pilot.press("enter")
assert pilot.app.selection is not None
Expand All @@ -57,7 +57,7 @@ async def test_with_run_on_select_off() -> None:
assert isinstance(pilot.app, CommandPaletteDoNotRunOnSelectApp)
pilot.app.action_command_palette()
await pilot.press("0")
await pilot.app.screen.workers.wait_for_complete()
await pilot.app.workers.wait_for_complete()
await pilot.press("down")
await pilot.press("enter")
assert pilot.app.selection is None
Expand Down
4 changes: 2 additions & 2 deletions tests/snapshot_tests/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -806,15 +806,15 @@ async def run_before(pilot) -> None:
# await pilot.press("ctrl+backslash")
pilot.app.screen.query_one(Input).cursor_blink = False
await pilot.press("A")
await pilot.app.screen.workers.wait_for_complete()
await pilot.app.workers.wait_for_complete()

assert snap_compare(SNAPSHOT_APPS_DIR / "command_palette.py", run_before=run_before)


def test_command_palette_discovery(snap_compare) -> None:
async def run_before(pilot) -> None:
pilot.app.screen.query_one(Input).cursor_blink = False
await pilot.app.screen.workers.wait_for_complete()
await pilot.app.workers.wait_for_complete()

assert snap_compare(
SNAPSHOT_APPS_DIR / "command_palette_discovery.py", run_before=run_before
Expand Down
Loading