Skip to content

Commit

Permalink
Fix runtime instantation of objects that don't define `__class_getite…
Browse files Browse the repository at this point in the history
…m__`
  • Loading branch information
CoolCat467 committed Oct 18, 2023
1 parent e873df1 commit ef91fb7
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
3 changes: 2 additions & 1 deletion trio/_core/_tests/test_guest_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Callable,
NoReturn,
TypeVar,
cast,
)

import pytest
Expand Down Expand Up @@ -458,7 +459,7 @@ async def trio_main() -> str:
print("trio_main!")

to_trio, from_aio = trio.open_memory_channel[int](float("inf"))
from_trio = asyncio.Queue[int]()
from_trio = cast("asyncio.Queue[int]", asyncio.Queue)()

aio_task = asyncio.ensure_future(aio_pingpong(from_trio, to_trio))

Expand Down
8 changes: 4 additions & 4 deletions trio/_core/_tests/test_thread_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import time
from contextlib import contextmanager
from queue import Queue
from typing import Iterator, NoReturn
from typing import Iterator, NoReturn, cast

import pytest
from outcome import Outcome
Expand All @@ -16,7 +16,7 @@


def test_thread_cache_basics() -> None:
q = Queue[Outcome]()
q = cast("Queue[Outcome]", Queue)()

def fn() -> NoReturn:
raise RuntimeError("hi")
Expand All @@ -41,7 +41,7 @@ def __call__(self) -> int:
def __del__(self) -> None:
res[0] = True

q = Queue[Outcome]()
q = cast("Queue[Outcome]", Queue)()

def deliver(outcome: Outcome) -> None:
q.put(outcome)
Expand All @@ -64,7 +64,7 @@ def test_spawning_new_thread_from_deliver_reuses_starting_thread() -> None:

# Make sure there are a few threads running, so if we weren't LIFO then we
# could grab the wrong one.
q = Queue[Outcome]()
q = cast("Queue[Outcome]", Queue)()
COUNT = 5
for _ in range(COUNT):
start_thread_soon(lambda: time.sleep(1), lambda result: q.put(result))
Expand Down
13 changes: 7 additions & 6 deletions trio/_tests/test_threads.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
Type,
TypeVar,
Union,
cast,
)

import pytest
Expand Down Expand Up @@ -346,7 +347,7 @@ async def child(q: stdlib_queue.Queue[None], cancellable: bool) -> None:
record.append("exit")

record: list[str] = []
q = stdlib_queue.Queue[None]()
q = cast("stdlib_queue.Queue[None]", stdlib_queue.Queue)()

Check failure on line 350 in trio/_tests/test_threads.py

View workflow job for this annotation

GitHub Actions / Ubuntu (3.8, check formatting)

Mypy-Linux+Mac+Windows

trio/_tests/test_threads.py:(350:9 - 350:62): "Queue[None]" not callable [operator]
async with _core.open_nursery() as nursery:
nursery.start_soon(child, q, True)
# Give it a chance to get started. (This is important because
Expand Down Expand Up @@ -394,8 +395,8 @@ def test_run_in_worker_thread_abandoned(
) -> None:
monkeypatch.setattr(_core._thread_cache, "IDLE_TIMEOUT", 0.01)

q1 = stdlib_queue.Queue[None]()
q2 = stdlib_queue.Queue[threading.Thread]()
q1 = cast("stdlib_queue.Queue[None]", stdlib_queue.Queue)()

Check failure on line 398 in trio/_tests/test_threads.py

View workflow job for this annotation

GitHub Actions / Ubuntu (3.8, check formatting)

Mypy-Linux+Mac+Windows

trio/_tests/test_threads.py:(398:10 - 398:63): "Queue[None]" not callable [operator]
q2 = cast("stdlib_queue.Queue[threading.Thread]", stdlib_queue.Queue)()

Check failure on line 399 in trio/_tests/test_threads.py

View workflow job for this annotation

GitHub Actions / Ubuntu (3.8, check formatting)

Mypy-Linux+Mac+Windows

trio/_tests/test_threads.py:(399:10 - 399:75): "Queue[Thread]" not callable [operator]

def thread_fn() -> None:
q1.get()
Expand Down Expand Up @@ -918,7 +919,7 @@ def get_tid_then_reenter() -> int:


async def test_from_thread_host_cancelled() -> None:
queue = stdlib_queue.Queue[bool]()
queue = cast("stdlib_queue.Queue[bool]", stdlib_queue.Queue)()

Check failure on line 922 in trio/_tests/test_threads.py

View workflow job for this annotation

GitHub Actions / Ubuntu (3.8, check formatting)

Mypy-Linux+Mac+Windows

trio/_tests/test_threads.py:(922:13 - 922:66): "Queue[bool]" not callable [operator]

def sync_check() -> None:
from_thread_run_sync(cancel_scope.cancel)
Expand Down Expand Up @@ -977,7 +978,7 @@ async def async_time_bomb() -> None:


async def test_from_thread_check_cancelled() -> None:
q = stdlib_queue.Queue[str]()
q = cast("stdlib_queue.Queue[str]", stdlib_queue.Queue)()

async def child(cancellable: bool, scope: CancelScope) -> None:
with scope:
Expand Down Expand Up @@ -1057,7 +1058,7 @@ def f() -> None: # type: ignore[no-redef] # noqa: F811
async def test_from_thread_check_cancelled_raises_in_foreign_threads() -> None:
with pytest.raises(RuntimeError):
from_thread_check_cancelled()
q = stdlib_queue.Queue[Outcome]()
q = cast("stdlib_queue.Queue[Outcome]", stdlib_queue.Queue)()
_core.start_thread_soon(from_thread_check_cancelled, lambda _: q.put(_))
with pytest.raises(RuntimeError):
q.get(timeout=1).unwrap()

0 comments on commit ef91fb7

Please sign in to comment.