diff --git a/setup.py b/setup.py index 732fa7acd7..5c5890d8a5 100644 --- a/setup.py +++ b/setup.py @@ -81,7 +81,7 @@ install_requires=[ "attrs >= 19.2.0", # for eq "sortedcontainers", - "async_generator >= 1.9", + "contextlib2; python_version < '3.10'", "idna", "outcome", "sniffio", diff --git a/test-requirements.in b/test-requirements.in index 99854204d6..16463dcb47 100644 --- a/test-requirements.in +++ b/test-requirements.in @@ -1,12 +1,13 @@ # For tests -pytest >= 5.0 # for faulthandler in core +pytest >= 5.0 # for faulthandler in core pytest-cov >= 2.6.0 -ipython # for the IPython traceback integration tests -pyOpenSSL # for the ssl tests -trustme # for the ssl tests -pylint # for pylint finding all symbols tests -jedi # for jedi code completion tests -cryptography>=36.0.0 # 35.0.0 is transitive but fails +ipython # for the IPython traceback integration tests +pyOpenSSL # for the ssl tests +trustme # for the ssl tests +pylint # for pylint finding all symbols tests +jedi # for jedi code completion tests +cryptography>=36.0.0 # 35.0.0 is transitive but fails +async_generator >= 1.9 # for testing against py3.5 style async generator wrappers # Tools black; implementation_name == "cpython" @@ -24,7 +25,7 @@ typing-extensions; implementation_name == "cpython" cffi; os_name == "nt" attrs >= 19.2.0 sortedcontainers -async_generator >= 1.9 +contextlib2; python_version < '3.10' idna outcome sniffio diff --git a/test-requirements.txt b/test-requirements.txt index f1162efdb0..974d3862fd 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -23,6 +23,8 @@ cffi==1.15.0 # via cryptography click==8.0.3 # via black +contextlib2==21.6.0 ; python_version < "3.10" + # via -r test-requirements.in coverage[toml]==6.0.2 # via pytest-cov cryptography==36.0.1 @@ -38,8 +40,6 @@ idna==3.3 # via # -r test-requirements.in # trustme -immutables==0.16 - # via -r test-requirements.in importlib-metadata==4.2.0 # via # click @@ -149,7 +149,6 @@ typing-extensions==3.10.0.2 ; implementation_name == "cpython" # -r test-requirements.in # astroid # black - # immutables # importlib-metadata # mypy # pylint diff --git a/trio/_core/_ki.py b/trio/_core/_ki.py index 36aacecd96..fdf396a3a3 100644 --- a/trio/_core/_ki.py +++ b/trio/_core/_ki.py @@ -4,8 +4,6 @@ from functools import wraps import attr -import async_generator - from .._util import is_main_thread if False: @@ -141,7 +139,7 @@ def wrapper(*args, **kwargs): return gen return wrapper - elif async_generator.isasyncgenfunction(fn): + elif inspect.isasyncgenfunction(fn): @wraps(fn) def wrapper(*args, **kwargs): diff --git a/trio/_core/tests/test_asyncgen.py b/trio/_core/tests/test_asyncgen.py index 6ce0af366f..983c2852c1 100644 --- a/trio/_core/tests/test_asyncgen.py +++ b/trio/_core/tests/test_asyncgen.py @@ -2,11 +2,14 @@ import weakref import pytest from math import inf -from functools import partial -from async_generator import aclosing from ... import _core from .tutil import gc_collect_harder, buggy_pypy_asyncgens, restore_unraisablehook +if sys.version_info >= (3, 10): + from contextlib import aclosing +else: + from contextlib2 import aclosing + def test_asyncgen_basics(): collected = [] diff --git a/trio/_util.py b/trio/_util.py index b5a2ceabdc..deebd66a7e 100644 --- a/trio/_util.py +++ b/trio/_util.py @@ -5,14 +5,11 @@ from abc import ABCMeta import os import signal -import sys -import pathlib -from functools import wraps, update_wrapper +from functools import update_wrapper import typing as t import threading import collections - -from async_generator import isasyncgen +from inspect import isasyncgen import trio @@ -334,8 +331,4 @@ def name_asyncgen(agen): module = agen.ag_frame.f_globals["__name__"] except (AttributeError, KeyError): module = "<{}>".format(agen.ag_code.co_filename) - try: - qualname = agen.__qualname__ - except AttributeError: - qualname = agen.ag_code.co_name - return f"{module}.{qualname}" + return f"{module}.{agen.__qualname__}" diff --git a/trio/testing/_sequencer.py b/trio/testing/_sequencer.py index a7e6e50ff0..c4e34717a1 100644 --- a/trio/testing/_sequencer.py +++ b/trio/testing/_sequencer.py @@ -1,7 +1,7 @@ from collections import defaultdict +from contextlib import asynccontextmanager import attr -from async_generator import asynccontextmanager from .. import _core from .. import _util diff --git a/trio/tests/test_ssl.py b/trio/tests/test_ssl.py index 10e6c13d8f..fee4063b74 100644 --- a/trio/tests/test_ssl.py +++ b/trio/tests/test_ssl.py @@ -6,12 +6,11 @@ import threading import socket as stdlib_socket import ssl -from contextlib import contextmanager +from contextlib import asynccontextmanager, contextmanager from functools import partial from OpenSSL import SSL import trustme -from async_generator import asynccontextmanager import trio from .. import _core diff --git a/trio/tests/test_subprocess.py b/trio/tests/test_subprocess.py index 65abe13e50..6065c3f11c 100644 --- a/trio/tests/test_subprocess.py +++ b/trio/tests/test_subprocess.py @@ -3,11 +3,11 @@ import signal import subprocess import sys +from contextlib import asynccontextmanager from functools import partial from pathlib import Path as SyncPath import pytest -from async_generator import asynccontextmanager from .. import ( ClosedResourceError,