Skip to content

Commit c1f37a9

Browse files
committed
Fix metadata handling for py38 and py39 venv environments
importlib.metadata in Python 3.10 had improved handling of certain virtual environments. This change addresses the issue with some venv environments not returning a version string for AnyIO.
1 parent f3bd068 commit c1f37a9

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

asyncer/_compat.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
# AnyIO 4.1.0 renamed cancellable to abandon_on_cancel
2-
import importlib
3-
import importlib.metadata
2+
import sys
43
from typing import Callable, TypeVar, Union
54

65
import anyio
76
import anyio.to_thread
87
from anyio import CapacityLimiter
98
from typing_extensions import TypeVarTuple, Unpack
109

11-
ANYIO_VERSION = importlib.metadata.version("anyio")
10+
if sys.version_info < (3, 10):
11+
from importlib_metadata import version as get_version
12+
else:
13+
from importlib.metadata import version as get_version
14+
15+
ANYIO_VERSION = get_version("anyio")
1216

1317
T_Retval = TypeVar("T_Retval")
1418
PosArgsT = TypeVarTuple("PosArgsT")

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ classifiers = [
3232
]
3333
dependencies = [
3434
"anyio >=3.4.0,<5.0",
35-
"typing_extensions >=4.8.0; python_version < '3.10'"
35+
"importlib-metadata >=4.6; python_version < '3.10'",
36+
"typing_extensions >=4.8.0; python_version < '3.10'",
3637
]
3738

3839
[project.urls]

0 commit comments

Comments
 (0)