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

Hashable and List are considered overlapping #7328

Closed
shoyer opened this issue Aug 13, 2019 · 1 comment
Closed

Hashable and List are considered overlapping #7328

shoyer opened this issue Aug 13, 2019 · 1 comment

Comments

@shoyer
Copy link

shoyer commented Aug 13, 2019

I think this is a bug:

from typing import Hashable, List, overload

@overload
def f(x: Hashable) -> str: ...

@overload
def f(x: List) -> str: ...

def f(x):
    return repr(x)

mypy (0.720) reports:

typing_test.py:7: error: Overloaded function signature 2 will never be matched: signature 1's parameter type(s) are the same or broader

I would expect this to work without complaints. Python lists are not hashable, unless you make some strange subclass.

@ilevkivskyi
Copy link
Member

This a known problem, and is not a purely mypy issue, but more like a typeshed one, see python/typeshed#2148. TBH, I don't see a problem in having few __hash__: None # type: ignore added to most used non-hashable classes.

nbren12 added a commit to nbren12/xarray that referenced this issue Jun 10, 2020
Sadly this is not working with my version of mypy. See python/mypy#7328
crusaderky added a commit to pydata/xarray that referenced this issue Jun 15, 2020
* Improve typehints of xr.Dataset.__getitem__

Resolves #4125

* Add overload for Mapping behavior

Sadly this is not working with my version of mypy. See python/mypy#7328

* Overload only Hashable inputs

Given mypy's use of overloads, I think this is all we can do. If the argument is not Hashable, then return the Union type as before.

* Lint

* Quote the DataArray to avoid error in py3.6

* Code review

Co-authored-by: crusaderky <[email protected]>
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

No branches or pull requests

2 participants