Skip to content

Commit

Permalink
Fix type hinting for .joinpath
Browse files Browse the repository at this point in the history
Type hinting was taking its cue from the multimethod decorator, so
joinpath was always returning Any as the type. To resolve, the
multimethod decorator has been annotated with generics so that the
typing system can correctly infer the return type of joinpath.
  • Loading branch information
SethMMorton committed Dec 21, 2024
1 parent 466a031 commit 667a82a
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions path/classes.pyi
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from typing import Any, Callable, Optional
from typing import Any, Callable, Generic, TypeVar, overload

class ClassProperty(property):
def __get__(self, cls: Any, owner: type | None = ...) -> Any: ...

class multimethod:
def __init__(self, func: Callable[..., Any]): ...
def __get__(self, instance: Any, owner: type | None) -> Any: ...
_T = TypeVar("_T")

class multimethod(Generic[_T]):
def __init__(self, func: Callable[..., _T]): ...
@overload
def __get__(self, instance: None, owner: type[_T] | None) -> Callable[..., _T]: ...
@overload
def __get__(self, instance: _T, owner: type[_T] | None) -> Callable[..., _T]: ...

0 comments on commit 667a82a

Please sign in to comment.