From 2dc81655d244add90068951b026865f5f6e48c7c Mon Sep 17 00:00:00 2001 From: Seth Morton Date: Sat, 21 Dec 2024 10:20:57 -0800 Subject: [PATCH] Fix type hinting for .joinpath 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. --- path/classes.pyi | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/path/classes.pyi b/path/classes.pyi index 0e119d0..4f23e41 100644 --- a/path/classes.pyi +++ b/path/classes.pyi @@ -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]: ...