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

Custom __iter__ method yields false positive when used with star args (*) #14470

Open
flaeppe opened this issue Jan 18, 2023 · 1 comment · May be fixed by #14496
Open

Custom __iter__ method yields false positive when used with star args (*) #14470

flaeppe opened this issue Jan 18, 2023 · 1 comment · May be fixed by #14496
Labels
bug mypy got something wrong

Comments

@flaeppe
Copy link

flaeppe commented Jan 18, 2023

Bug Report

Custom implemented __iter__ method on class mismatches when passing positional arguments with asterisk(*)

To Reproduce

from typing import Iterator

class X:
    def __iter__(self) -> Iterator[str]:
        return iter([""])


def func(*args: int) -> None:
    return None

        
func(*X())  # OK (false positive, should have incompatible type error)
func(*X().__iter__())  # 13: error: Argument 1 to "func" has incompatible type "*Iterator[str]"; expected "int"  [arg-type]

Expected Behavior

Mypy should yield an error when passing positional parameters with asterisk(*) that do not match the expected type.

In this case it should complain on the function call on line 12, as it calls func with a mismatching type of iterable.

Actual Behavior

Passing iterator with only * yields no error.

Your Environment

  • Mypy version used: 0.991
  • Mypy command-line flags: -
  • Mypy configuration options from mypy.ini (and other config files):
  • Python version used: 3.11
@flaeppe flaeppe added the bug mypy got something wrong label Jan 18, 2023
@erictraut
Copy link

I think the bug here is a false negative, not a false positive. Mypy fails to emit an error for the expression func(*X()) when this is a type violation. By contrast, pyright emits an error on this line.

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

Successfully merging a pull request may close this issue.

2 participants