Skip to content

Commit

Permalink
feat: mypy dispatcher
Browse files Browse the repository at this point in the history
Signed-off-by: nstarman <[email protected]>
  • Loading branch information
nstarman committed Jun 29, 2024
1 parent e1afac1 commit 1133686
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ repos:
(?x)
^(
| plum/alias\.py
| plum/dispatcher\.py
| plum/function\.py
| plum/method\.py
| plum/parametric\.py
Expand Down
2 changes: 1 addition & 1 deletion plum/autoreload.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def _update_instances(old: type, new: type) -> None:
type_mapping[k] = v

# Since types have changed, clear the cache of everything.
clear_all_cache() # type: ignore[no-untyped-call]
clear_all_cache()


_update_instances_original = None
Expand Down
8 changes: 4 additions & 4 deletions plum/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ class Dispatcher:
classes: Dict[str, Dict[str, Function]] = field(default_factory=dict)

@overload
def __call__(self, method: T, precedence: int = ...) -> T: ...
def __call__(self, method: None, precedence: int) -> Callable[[T], T]: ...

@overload
def __call__(self, method: None, precedence: int) -> Callable[[T], T]: ...
def __call__(self, method: T, precedence: int = ...) -> T: ...

def __call__(
self, method: Optional[T] = None, precedence: int = 0
Expand Down Expand Up @@ -130,13 +130,13 @@ def _add_method(
f.register(method, signature, precedence)
return f

def clear_cache(self):
def clear_cache(self) -> None:
"""Clear cache."""
for f in self.functions.values():
f.clear_cache()


def clear_all_cache():
def clear_all_cache() -> None:
"""Clear all cache, including the cache of subclass checks. This should be called
if types are modified."""
for f in Function._instances:
Expand Down

0 comments on commit 1133686

Please sign in to comment.