Skip to content

Improve typing coverage with ParamSpec + Protocol#27

Merged
toloco merged 2 commits into
masterfrom
improve-typing
Apr 13, 2026
Merged

Improve typing coverage with ParamSpec + Protocol#27
toloco merged 2 commits into
masterfrom
improve-typing

Conversation

@toloco
Copy link
Copy Markdown
Owner

@toloco toloco commented Apr 13, 2026

Summary

  • Added CachedCallable[P, R] protocol — preserves the original function's call signature while exposing cache_info() and cache_clear()
  • Added BaseCacheInfo protocol — common interface for cache info objects (hits, misses, max_size, current_size)
  • cache() return type updated from Callable[[F], F] to Callable[[Callable[P, R]], CachedCallable[P, R]]
  • Added _probe to _warp_cache_rs.pyi stub (removes type: ignore comments)
  • typing_extensions dependency for Python 3.9 only

Closes #10

Before

@cache(max_size=128)
def add(x: int, y: int) -> int: ...

add.cache_info()  # type error: no attribute 'cache_info'

After

@cache(max_size=128)
def add(x: int, y: int) -> int: ...

add(1, 2)          # type: int
add.cache_info()   # type: BaseCacheInfo
add.cache_clear()  # OK

Test plan

  • ty check passes with zero diagnostics
  • ruff check passes
  • All 79 existing tests pass
  • New exports verified: from warp_cache import CachedCallable, BaseCacheInfo

🤖 Generated with Claude Code

toloco and others added 2 commits April 13, 2026 14:28
Add CachedCallable[P, R] protocol that preserves the original function's
call signature while exposing cache_info() and cache_clear(). Add
BaseCacheInfo protocol for the common cache info interface.

- cache() now returns Callable[[Callable[P, R]], CachedCallable[P, R]]
- Add _probe to _warp_cache_rs.pyi stub (removes type:ignore comments)
- Export BaseCacheInfo and CachedCallable from warp_cache
- Add typing_extensions dependency for Python 3.9

Closes #10

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@toloco toloco merged commit 40e55c2 into master Apr 13, 2026
15 checks passed
@toloco toloco deleted the improve-typing branch April 13, 2026 17:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve typing coverage

1 participant