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

Mypy does not report as an error passing a list[str] where tuple[str, ...] is expected. #16576

Open
slothyrulez opened this issue Nov 27, 2023 · 4 comments
Labels
bug mypy got something wrong

Comments

@slothyrulez
Copy link

Bug Report

Mypy does not report as a bug passing a list[str] where tuple[str, ...] is expected.

To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=032e779ff0e6eb9f72a3c902a9f6dba7

Expected Behavior

imagen

Mypy identifies the issue.

Actual Behavior

mypy /tmp/mypy_error.py 
Success: no issues found in 1 source file

Your Environment

  • Mypy version used: 1.7.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): None
  • Python version used: 3.11
@slothyrulez slothyrulez added the bug mypy got something wrong label Nov 27, 2023
@JelleZijlstra
Copy link
Member

Thanks for the report, but please try to minimize your bug reports so it easier to see the issue. I haven't looked very closely but this seems related to functools.partial and therefore quite possibly a duplicate of #1484.

@slothyrulez
Copy link
Author

Thanks for the report, but please try to minimize your bug reports so it easier to see the issue. I haven't looked very closely but this seems related to functools.partial and therefore quite possibly a duplicate of #1484.

Yes, sorry, I'm not really sure where the issue is, so I just wrote an example that reproduces the issue. Indeed there is a funtools.partial involved.

@JelleZijlstra
Copy link
Member

Then the way to minimize is to remove code from the example until you get the simplest possible example that still shows the problem.

@slothyrulez
Copy link
Author

slothyrulez commented Nov 27, 2023

Thanks @JelleZijlstra, a reduced version:

from __future__ import annotations

import functools
from typing import Callable, TypeVar

TR = TypeVar("TR")


def dummy(key_callable: Callable[[], str], value_callable: Callable[[], TR]) -> TR:
    _ = key_callable()
    value = value_callable()
    return value


class Thing:
    def _get_cache_key(self, obj_id: str, expand: tuple[str, ...]) -> str:
        return f"key.{obj_id}{'.'.join(expand)}"

    def _get_an_object(self, obj_id: str, expand: list[str]) -> str:
        return f"value.{obj_id}{'.'.join(expand)}"

    def get_obj(self, obj_id: str, expand: list[str]) -> str:
        return dummy(
            functools.partial(self._get_cache_key, obj_id, expand),
            functools.partial(self._get_an_object, obj_id, expand),
        )

https://mypy-play.net/?mypy=latest&python=3.11&gist=e258fc60b107eecfe1754db8311c9c6f

imagen
imagen

@slothyrulez slothyrulez changed the title Mypy does not report as a bug passing a list[str] where tuple[str, ...] is expected. Mypy does not report as an error passing a list[str] where tuple[str, ...] is expected. Nov 28, 2023
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