Skip to content

Commit

Permalink
ensure that pickling TaskInfo fails with a TypeError
Browse files Browse the repository at this point in the history
  • Loading branch information
graingert committed May 12, 2021
1 parent 9b14209 commit 4b76b93
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
7 changes: 1 addition & 6 deletions src/anyio/_core/_testing.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Coroutine, Generator, Optional, Tuple, Type
from typing import Coroutine, Generator, Optional

from ._compat import DeprecatedAwaitableList, _warn_deprecation
from ._eventloop import get_asynclib
Expand Down Expand Up @@ -43,11 +43,6 @@ def __await__(self) -> Generator[None, None, "TaskInfo"]:
yield
return self

def __reduce__(self) -> Tuple[
Type["TaskInfo"], Tuple[int, Optional[int], Optional[str], Coroutine]
]:
return TaskInfo, (self.id, self.parent_id, self.name, self.coro)

def _unwrap(self) -> 'TaskInfo':
return self

Expand Down
5 changes: 5 additions & 0 deletions tests/test_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,8 @@ def test_deprecated_awaitable_list(self):
result = pickle.loads(pickle.dumps(obj))
assert type(result) is list
assert result == [1, 'a']

async def test_deprecated_awaitable_task_info(self):
task = get_current_task()
with pytest.raises(TypeError): # previously pickled as None
pickle.dumps(task)

0 comments on commit 4b76b93

Please sign in to comment.