Skip to content

Commit

Permalink
Fix masking of _typings as Any
Browse files Browse the repository at this point in the history
  - 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
  • Loading branch information
mikeshardmind committed Jan 15, 2025
1 parent 4536ceb commit 275c037
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/async_utils/_typings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@

if TYPE_CHECKING:
from typing import Any, Literal, Never, Self
else:

def __getattr__(name: str):
if name in {"Any", "Literal", "Never", "Self"}:
import typing

def __getattr__(name: str):
if name in {"Any", "Literal", "Never", "Self"}:
import typing
return getattr(typing, name)

return getattr(typing, name)

msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)
msg = f"module {__name__!r} has no attribute {name!r}"
raise AttributeError(msg)


__all__ = ["Any", "Literal", "Never", "Self"]
4 changes: 2 additions & 2 deletions src/async_utils/corofunc_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
type CoroFunc[**P, R] = Callable[P, Coroutine[t.Any, t.Any, R]]
type CoroLike[**P, R] = Callable[P, Awaitable[R]]

type _CT_RET = tuple[tuple[t.Any, ...], dict[t.str, t.Any]]
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[t.str, t.Any]], _CT_RET]
type _CT_RET = tuple[tuple[t.Any, ...], dict[str, t.Any]]
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[str, t.Any]], _CT_RET]

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

Expand Down
4 changes: 2 additions & 2 deletions src/async_utils/task_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
type TaskFunc[**P, R] = CoroFunc[P, R] | Callable[P, asyncio.Task[R]]
type TaskCoroFunc[**P, R] = CoroFunc[P, R] | TaskFunc[P, R]

type _CT_RET = tuple[tuple[t.Any, ...], dict[t.str, t.Any]]
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[t.str, t.Any]], _CT_RET]
type _CT_RET = tuple[tuple[t.Any, ...], dict[str, t.Any]]
type CacheTransformer = Callable[[tuple[t.Any, ...], dict[str, t.Any]], _CT_RET]

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

Expand Down

0 comments on commit 275c037

Please sign in to comment.