Skip to content

Commit 275c037

Browse files
committed
Fix masking of _typings as Any
- move `__getattr__` into the else branch if the TYPE_CHECKING conditional. This prevents pyright from seeing it and masking values. I was unaware pyright had any support for module __getattr__ - Fixup a few unintentional instances of t.str resolves #6
1 parent 4536ceb commit 275c037

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/async_utils/_typings.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@
3030

3131
if TYPE_CHECKING:
3232
from typing import Any, Literal, Never, Self
33+
else:
3334

35+
def __getattr__(name: str):
36+
if name in {"Any", "Literal", "Never", "Self"}:
37+
import typing
3438

35-
def __getattr__(name: str):
36-
if name in {"Any", "Literal", "Never", "Self"}:
37-
import typing
39+
return getattr(typing, name)
3840

39-
return getattr(typing, name)
40-
41-
msg = f"module {__name__!r} has no attribute {name!r}"
42-
raise AttributeError(msg)
41+
msg = f"module {__name__!r} has no attribute {name!r}"
42+
raise AttributeError(msg)
4343

4444

4545
__all__ = ["Any", "Literal", "Never", "Self"]

src/async_utils/corofunc_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
type CoroFunc[**P, R] = Callable[P, Coroutine[t.Any, t.Any, R]]
2929
type CoroLike[**P, R] = Callable[P, Awaitable[R]]
3030

31-
type _CT_RET = tuple[tuple[t.Any, ...], dict[t.str, t.Any]]
32-
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[t.str, t.Any]], _CT_RET]
31+
type _CT_RET = tuple[tuple[t.Any, ...], dict[str, t.Any]]
32+
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[str, t.Any]], _CT_RET]
3333

3434
type Deco[**P, R] = Callable[[CoroLike[P, R]], CoroFunc[P, R]]
3535

src/async_utils/task_cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
type TaskFunc[**P, R] = CoroFunc[P, R] | Callable[P, asyncio.Task[R]]
3232
type TaskCoroFunc[**P, R] = CoroFunc[P, R] | TaskFunc[P, R]
3333

34-
type _CT_RET = tuple[tuple[t.Any, ...], dict[t.str, t.Any]]
35-
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[t.str, t.Any]], _CT_RET]
34+
type _CT_RET = tuple[tuple[t.Any, ...], dict[str, t.Any]]
35+
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[str, t.Any]], _CT_RET]
3636

3737
type Deco[**P, R] = Callable[[TaskCoroFunc[P, R]], TaskFunc[P, R]]
3838

0 commit comments

Comments
 (0)