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

reveal_type() may affect inferred type / overload resolution #6328

Open
JukkaL opened this issue Feb 4, 2019 · 1 comment
Open

reveal_type() may affect inferred type / overload resolution #6328

JukkaL opened this issue Feb 4, 2019 · 1 comment
Labels
bug mypy got something wrong priority-1-normal topic-reveal-type reveal_type() and reveal_locals()

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Feb 4, 2019

The first filter call below generates an error when using --py2, but the same call without reveal_type(...) is fine:

from typing import Any, List

a = 0  # type: Any

x = filter(None, reveal_type(a))  # type: List[str]  # Error
x2 = filter(None, a)  # type: List[str]  # No error

The error message is Incompatible types in assignment (expression has type "Tuple[<nothing>, ...]", variable has type "List[str]").

reveal_type should have no effect on inferred types, since it's often used to diagnose issues with type inference.

@ilevkivskyi ilevkivskyi added bug mypy got something wrong priority-1-normal labels Feb 5, 2019
@AlexWaygood AlexWaygood added the topic-reveal-type reveal_type() and reveal_locals() label Mar 29, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Mar 29, 2022

This error is still reproduceable if you run mypy with --python-version 2.7. It's also reproduceable with Python 3 set as the Python version, if you copy-paste typeshed's Python-2 stub for filter into a file:

from typing import *

_T = TypeVar("_T")

a = 0  # type: Any

@overload  # type: ignore[no-overload-impl]
def py2_filter(__function: Callable[[AnyStr], Any], __iterable: AnyStr) -> AnyStr: ...  # type: ignore
@overload
def py2_filter(__function: None, __iterable: tuple[_T | None, ...]) -> tuple[_T, ...]: ...  # type: ignore
@overload
def py2_filter(__function: Callable[[_T], Any], __iterable: tuple[_T, ...]) -> tuple[_T, ...]: ...  # type: ignore
@overload
def py2_filter(__function: None, __iterable: Iterable[_T | None]) -> list[_T]: ...
@overload
def py2_filter(__function: Callable[[_T], Any], __iterable: Iterable[_T]) -> list[_T]: ...

y = py2_filter(None, reveal_type(a))  # type: List[str]  # Error
y2 = py2_filter(None, a)  # type: List[str]  # No error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong priority-1-normal topic-reveal-type reveal_type() and reveal_locals()
Projects
None yet
Development

No branches or pull requests

3 participants