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

Two more issues with overloads and --no-strict-optional #5246

Closed
ilevkivskyi opened this issue Jun 19, 2018 · 1 comment
Closed

Two more issues with overloads and --no-strict-optional #5246

ilevkivskyi opened this issue Jun 19, 2018 · 1 comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-overloads topic-strict-optional

Comments

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Jun 19, 2018

Here are some new false positives with overloads, based on real code samples with map in Python 2.
The bug(s) only appear if the strict optional is disabled:

from typing import TypeVar, Iterable, Tuple, List, overload, Callable
S = TypeVar('S')
T1 = TypeVar('T1')
T2 = TypeVar('T2')

@overload
def map1(func: Callable[[T1], S], iter1: Iterable[T1]) -> List[S]: ...
@overload
def map1(func: None, iter1: Iterable[T1]) -> List[T1]: ...
def map1(*args, **kwargs):
    pass

a: List[int]
b: List[str]

for x in map1(None, a):  # false positive: Need type annotation for 'x'
    pass

@overload
def map2(func: Callable[[T1, T2], S],
        iter1: Iterable[T1],
        iter2: Iterable[T2]) -> List[S]: ...
@overload
def map2(func: None,
        iter1: Iterable[T1],
        iter2: Iterable[T2]) -> List[Tuple[T1, T2]]: ...
def map2(*args, **kwargs):
    pass

for y, z in map2(None, a, b):  # false positive: '<nothing>' object is not iterable
    pass
@Michael0x2a
Copy link
Collaborator

A temporary workaround would be to swap the order of the overloads so the one with func: None always comes first.

I'll look into adding a more robust fix.

Michael0x2a added a commit to Michael0x2a/typeshed that referenced this issue Jun 20, 2018
…irst

In short, this change makes sure calls like `map(None, a, b)` behave as
expected when using `--no-strict-optional` is enabled.

For additional context, see python/mypy#5246
Michael0x2a added a commit to Michael0x2a/mypy that referenced this issue Jun 20, 2018
Resolves python#5246

Previously, we force-enabled strict optional checks when performing all
overload definition checks. This ended up causing mypy to miss some
errors in definitions when `--no-strict-optional` mode is enabled.

This commit will now force-enable strict optional only when checking if
overloads are unsafely overlapping: we use the existing mode when
checking if one variant completely eclipses another or when checking the
implementation.
JelleZijlstra pushed a commit to python/typeshed that referenced this issue Jun 20, 2018
…irst (#2261)

In short, this change makes sure calls like `map(None, a, b)` behave as
expected when using `--no-strict-optional` is enabled.

For additional context, see python/mypy#5246
Michael0x2a added a commit to Michael0x2a/mypy that referenced this issue Jun 20, 2018
Resolves python#5246

Previously, we force-enabled strict optional checks when performing all
overload definition checks. This ended up causing mypy to miss some
errors in definitions when `--no-strict-optional` mode is enabled.

This commit will now force-enable strict optional only when checking if
overloads are unsafely overlapping: we use the existing mode when
checking if one variant completely eclipses another or when checking the
implementation.
ilevkivskyi pushed a commit that referenced this issue Jun 21, 2018
…5252)

Resolves #5246

Previously, we force-enabled strict optional checks when performing all
overload definition checks. This ended up causing mypy to miss some
errors in definitions when `--no-strict-optional` mode is enabled.

This commit will now force-enable strict optional only when checking if
overloads are unsafely overlapping: we use the existing mode when
checking if one variant completely eclipses another or when checking the
implementation.
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this issue Jan 23, 2019
…irst (python#2261)

In short, this change makes sure calls like `map(None, a, b)` behave as
expected when using `--no-strict-optional` is enabled.

For additional context, see python/mypy#5246
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong false-positive mypy gave an error on correct code priority-1-normal topic-overloads topic-strict-optional
Projects
None yet
Development

No branches or pull requests

3 participants