Skip to content

Commit ecbc966

Browse files
committed
Slight future proofing on calls in type-expressions
1 parent f4cba94 commit ecbc966

File tree

4 files changed

+28
-8
lines changed

4 files changed

+28
-8
lines changed

_misc/_ensure_annotations.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ def version_specific_annotation_interactions(obj: Any) -> None:
7676

7777
print("Checking annotations for runtime validity", flush=True) # noqa: T201
7878

79-
for mod_info in pkgutil.iter_modules(async_utils.__spec__.submodule_search_locations):
79+
spec = async_utils.__spec__
80+
assert spec is not None
81+
locations = spec.submodule_search_locations
82+
83+
for mod_info in pkgutil.iter_modules(locations):
8084
mod = importlib.import_module(f"async_utils.{mod_info.name}")
8185
for name in getattr(mod, "__all__", ()):
8286
obj = getattr(mod, name)

src/async_utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
__author__ = "Michael Hall"
1010
__license__ = "Apache-2.0"
1111
__copyright__ = "Copyright 2020-Present Michael Hall"
12-
__version__ = "2025.06.25b"
12+
__version__ = "2025.07.02b"
1313

1414
import os
1515
import sys

src/async_utils/corofunc_cache.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,17 @@ def __call__[**P, R](self, c: CoroLike[P, R], /) -> CoroFunc[P, R]: ...
4646

4747
def f__call__[**P, R](self, c: CoroLike[P, R], /) -> CoroFunc[P, R]: ... # noqa: ANN001
4848

49-
type CoroCacheDeco = type(
50-
"CoroCacheDeco", (__import__("typing").Protocol,), {"__call__": f__call__}
51-
)
49+
class ExprWrapper:
50+
"""Future proof against runtime change preventing call expr in type statement."""
51+
52+
def __class_getitem__(cls, key: None) -> t.Any:
53+
return type(
54+
"CoroCacheDeco",
55+
(__import__("typing").Protocol,),
56+
{"__call__": f__call__},
57+
)
58+
59+
type CoroCacheDeco = ExprWrapper[None]
5260

5361

5462
def _chain_fut[R](c_fut: cf.Future[R], a_fut: asyncio.Future[R]) -> None:

src/async_utils/task_cache.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ def __call__[**P, R](self, c: TaskCoroFunc[P, R], /) -> TaskFunc[P, R]: ...
4747

4848
def f__call__[**P, R](self, c: TaskCoroFunc[P, R], /) -> TaskFunc[P, R]: ... # noqa: ANN001
4949

50-
type TaskCacheDeco = type(
51-
"TaskCacheDeco", (__import__("typing").Protocol,), {"__call__": f__call__}
52-
)
50+
class ExprWrapper:
51+
"""Future proof against runtime change preventing call expr in type statement."""
52+
53+
def __class_getitem__(cls, key: None) -> t.Any:
54+
return type(
55+
"TaskCacheDeco",
56+
(__import__("typing").Protocol,),
57+
{"__call__": f__call__},
58+
)
59+
60+
type TaskCacheDeco = ExprWrapper[None]
5361

5462

5563
# Non-annotation assignments for transformed functions

0 commit comments

Comments
 (0)