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

Spurious warning in situation involving bytes, overload, lambda #12666

Closed
hauntsaninja opened this issue Apr 24, 2022 · 1 comment
Closed

Spurious warning in situation involving bytes, overload, lambda #12666

hauntsaninja opened this issue Apr 24, 2022 · 1 comment
Labels
bug mypy got something wrong

Comments

@hauntsaninja
Copy link
Collaborator

Discovered as part of python/typeshed#7679

Given the following:

from typing import Any, Callable, overload

@overload
def sublike(pattern: str, repl: Callable[[str], str]) -> str: ...
@overload
def sublike(pattern: bytes, repl: Callable[[bytes], str]) -> bytes: ...
def sublike(*args, **kwargs) -> Any: ...

def minv1() -> str:
    return sublike("asdf", lambda m: f"{m}")

mypy produces:

test.py:10: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
Found 1 error in 1 file (checked 1 source file)

If you change to return sublike("asdf", reveal_type(lambda m: f"{m}")), you get:

asdf.py:10: note: Revealed type is "def (m: Any) -> builtins.str"
asdf.py:10: note: Revealed type is "def (builtins.str) -> builtins.str"
asdf.py:10: error: On Python 3 formatting "b'abc'" with "{}" produces "b'abc'", not "abc"; use "{!r}" if this is desired behavior
Found 1 error in 1 file (checked 1 source file)

So possibly related to the multipass logic for lambdas.

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