Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

functools.partial confuses mypy's type variable binding #10299

Closed
NeilGirdhar opened this issue Apr 8, 2021 · 1 comment
Closed

functools.partial confuses mypy's type variable binding #10299

NeilGirdhar opened this issue Apr 8, 2021 · 1 comment
Labels
bug mypy got something wrong

Comments

@NeilGirdhar
Copy link
Contributor

NeilGirdhar commented Apr 8, 2021

from functools import partial
from typing import Any, Callable, Generic, Tuple, TypeVar

ReturnValue = TypeVar('ReturnValue')

class custom_vjp(Generic[ReturnValue]):
  def __init__(self,
               fun: Callable[..., ReturnValue],
               nondiff_argnums: Tuple[int, ...] = ()):
      self.fun = fun

  def __call__(self, *args: Any, **kwargs: Any) -> ReturnValue:
      return self.fun(*args, **kwargs)

  def defvjp(self,
             fwd: Callable[..., Tuple[ReturnValue, Any]]) -> None:
      pass

# @custom_vjp  (works with this)
@partial(custom_vjp, nondiff_argnums=(0,))
def f() -> None:
    pass

def fwd() -> tuple[None, None]:
    return None, None

f.defvjp(fwd)

f()

gives

a.py:26: error: Argument 1 to "defvjp" of "custom_vjp" has incompatible type "Callable[[], Tuple[None, None]]"; expected "Callable[..., Tuple[ReturnValue, Any]]"
@NeilGirdhar NeilGirdhar added the bug mypy got something wrong label Apr 8, 2021
@hauntsaninja
Copy link
Collaborator

I think this works on latest master with the support Ivan and I added for functools.partial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants