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

Overloaded function signature will never be matched #16854

Closed
chiamp opened this issue Feb 2, 2024 · 1 comment
Closed

Overloaded function signature will never be matched #16854

chiamp opened this issue Feb 2, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@chiamp
Copy link

chiamp commented Feb 2, 2024

Bug Report
I get the following error when I add **init_kwargs to the first overloaded function signature. If I remove it (but keep **init_kwargs in all of the other function signatures), there's no error.

flax/linen/module.py:1664: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader  [misc]
flax/linen/module.py:1675: error: Overloaded function signature 3 will never be matched: signature 1's parameter type(s) are the same or broader  [misc]
flax/linen/module.py:1686: error: Overloaded function signature 4 will never be matched: signature 1's parameter type(s) are the same or broader  [misc]

To Reproduce

  @overload
  def param(
    self, name: str, init_fn: Callable[..., T], *init_args, **init_kwargs,
  ) -> T:
    ...

  @overload
  def param(
    self,
    name: str,
    init_fn: Callable[..., T],
    *init_args,
    unbox: Literal[True],
    **init_kwargs,
  ) -> T:
    ...

  @overload
  def param(
    self,
    name: str,
    init_fn: Callable[..., T],
    *init_args,
    unbox: Literal[False],
    **init_kwargs,
  ) -> meta.AxisMetadata[T]:
    ...

  @overload
  def param(
    self,
    name: str,
    init_fn: Callable[..., T],
    *init_args,
    unbox: bool,
    **init_kwargs,
  ) -> Union[T, meta.AxisMetadata[T]]:
    ...

  def param(
    self,
    name: str,
    init_fn: Callable[..., T],
    *init_args,
    unbox: bool = True,
    **init_kwargs,
  ) -> Union[T, meta.AxisMetadata[T]]:

Expected Behavior

Actual Behavior

Your Environment

  • Mypy version used: mypy 1.8.0 (compiled: yes)
  • Python version used: 3.9.6
@chiamp chiamp added the bug mypy got something wrong label Feb 2, 2024
@hauntsaninja
Copy link
Collaborator

This is a correct error. **init_kwargs will match all kwargs, so the second overload will never get matched

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale May 23, 2024
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