Skip to content

Improve overloads of parse_args() -- it never returns None #2643

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

Merged
merged 2 commits into from
Nov 28, 2018

Conversation

gvanrossum
Copy link
Member

Fixes #2641

@gvanrossum
Copy link
Member Author

Argh! The self-tests cause

mypy/typeshed/stdlib/2and3/argparse.pyi:128: error: Overloaded function signatures 2 and 3 overlap with incompatible return types
mypy/typeshed/stdlib/2and3/argparse.pyi:132: error: Overloaded function signatures 4 and 5 overlap with incompatible return types

even though type-checking something (like my example above) that imports argparse does not give this.

Any ideas?

@ilevkivskyi
Copy link
Member

The signatures are overlapping if --strict-optional is False.

@ilevkivskyi
Copy link
Member

Hm, it fails even with strict optional, a simple repro:

from typing import overload, TypeVar
  
T = TypeVar('T')

@overload
def f(x: None) -> int: ...
@overload
def f(x: T) -> T: ...
def f(x):
    pass

I would say this is a bug.

@ilevkivskyi
Copy link
Member

Well this is not a bug, sorry, if T is Optional[str], there is an unsafe overlap, there must be a bound for T.

@ilevkivskyi
Copy link
Member

I remember we discussed this with @Michael0x2a and were at the boundary of allowing this, because in practice the unsafety is quite minor. So I think it is fine to just # type: ignore this, if there is no way to put a bound on variable.

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@gvanrossum gvanrossum merged commit f9ba540 into master Nov 28, 2018
@JelleZijlstra JelleZijlstra deleted the fix-parse-args branch November 28, 2018 04:42
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants