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

no-overload-impl false positive with typevar inside #17167

Open
trim21 opened this issue Apr 24, 2024 · 1 comment
Open

no-overload-impl false positive with typevar inside #17167

trim21 opened this issue Apr 24, 2024 · 1 comment
Labels
bug mypy got something wrong

Comments

@trim21
Copy link

trim21 commented Apr 24, 2024

Bug Report

TypeVar after overload cause mypy raise a warning about missing impl and redef

(A clear and concise description of what the bug is.)

To Reproduce

from typing import Iterable, Sequence, TypeVar, overload


@overload
def chunks(c: str, n) -> Iterable[str]: ...


@overload
def chunks(c: bytes, n) -> Iterable[bytes]: ...


_T = TypeVar("_T")


def chunks(c: Sequence[_T], n) -> Iterable[Sequence[_T]]:
    # looping till length l
    for i in range(0, len(c), n):
        yield c[i : i + n]

Expected Behavior

should not report errors

Actual Behavior

a.py:4: error: An overloaded function outside a stub file must have an implementation [no-overload-impl]
a.py:15: error: Name "chunks" already defined on line 4 [no-redef]

Your Environment

  • Mypy version used: 1.9.0
  • Mypy command-line flags:
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.10
[tool.mypy]
allow_redefinition = true
ignore_missing_imports = true
check_untyped_defs = true
warn_no_return = false
@trim21 trim21 added the bug mypy got something wrong label Apr 24, 2024
@cdce8p
Copy link
Collaborator

cdce8p commented Apr 24, 2024

Try moving the TypeVar definition above the overloads. That will resolve the errors.

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