Skip to content

Confusion on return type of difflib.get_closest_matches #3906

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

Closed
deveshks opened this issue Apr 4, 2020 · 5 comments · Fixed by #3908
Closed

Confusion on return type of difflib.get_closest_matches #3906

deveshks opened this issue Apr 4, 2020 · 5 comments · Fixed by #3908

Comments

@deveshks
Copy link

deveshks commented Apr 4, 2020

There is a mismatch between the return type mentioned in the docs of difflib.get_close_matches (List[str]) vs what is mentioned in typeshed source code (List[Sequence[_T]])

This was observed when I was trying to add type annotations to https://github.com/pypa/pip/blob/master/src/pip/_internal/commands/__init__.py#L103

@McSinyx
Copy link
Contributor

McSinyx commented Apr 5, 2020

As you mentioned in the linked PR, this is a duplicate of GH-2067 (and python/mypy#1965). Generally it's not a good idea to re-file an issue. In this particular case, it is possible to cast the return value to List[str] however.

@deveshks
Copy link
Author

deveshks commented Apr 5, 2020

Hi @McSinyx

I had a discussion with @pradyunsg and he mentioned that #2067 is in fact definitely a different bug, hence I have filed this bug.

@pradyunsg
Copy link
Member

s/not a different/definitely a different/

@JelleZijlstra
Copy link
Member

This does sound like the same issue as #2067. As I said there, it's fixable with an overload, and I just submitted #3908 doing that.

Here's the relevant behavior:

In [10]: difflib.get_close_matches('x', ['y', 'zx'])                                                                                                                                              
Out[10]: ['zx']

In [11]: difflib.get_close_matches((1, 2, 3), [(1, 2), (1, 2, 3, 4)])                                                                                                                             
Out[11]: [(1, 2, 3, 4), (1, 2)]

@deveshks
Copy link
Author

deveshks commented Apr 5, 2020

Thanks @JelleZijlstra for the quickaround and the fix. Really appreciate it 😄

srittau pushed a commit that referenced this issue Apr 5, 2020
vishalkuo pushed a commit to vishalkuo/typeshed that referenced this issue Jun 26, 2020
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 a pull request may close this issue.

4 participants