From 5653f61d61efcba79beecd2395aeaa86595e899c Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sat, 28 May 2022 14:41:35 +0200 Subject: [PATCH] More workaround for mypy bug https://github.com/python/mypy/issues/708 --- src/factory-stubs/declarations.pyi | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/factory-stubs/declarations.pyi b/src/factory-stubs/declarations.pyi index 63af57d..0ba0b0a 100644 --- a/src/factory-stubs/declarations.pyi +++ b/src/factory-stubs/declarations.pyi @@ -49,13 +49,27 @@ class BaseDeclaration(Generic[T, V], utils.OrderedBase): class OrderedDeclaration(BaseDeclaration[T, V]): ... class LazyFunction(BaseDeclaration[T, V]): - function: Callable[[], V] + # Workaround for mypy bug https://github.com/python/mypy/issues/708 + # Otherwise it would just be this: + # function: Callable[[], V] + @staticmethod + def function() -> V : ... def __init__(self, function: Callable[[], V]) -> None: ... class LazyAttribute(BaseDeclaration[T, V]): - function: Callable[[builder.Resolver], V] + # Workaround for mypy bug https://github.com/python/mypy/issues/708 + # Otherwise it would just be this: + # function: Callable[[builder.Resolver], V] + @staticmethod + def function(obj: builder.Resolver, /) -> V: ... def __init__(self, function: Callable[[builder.Resolver], V]) -> None: ... +# TODO: Make sure that reveal_type(a) == LazyAttribute(dict[str, str], float: +# def floatify(o: dict[str, str]) -> float: +# return float(o['asd']) +# a = LazyAttribute(floatify) +# reveal_type(a) + class _UNSPECIFIED: ... def deepgetattr(obj: Any, name: str, default: _UNSPECIFIED | Any = ...) -> Any: ...