Skip to content

Commit

Permalink
More workaround for mypy bug python/mypy#708
Browse files Browse the repository at this point in the history
  • Loading branch information
alessio-b2c2 committed May 28, 2022
1 parent c7567b6 commit 5653f61
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/factory-stubs/declarations.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
Expand Down

0 comments on commit 5653f61

Please sign in to comment.