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

Function cannot be assigned to Hashable type #1027

Closed
MapleCCC opened this issue Mar 10, 2021 · 3 comments
Closed

Function cannot be assigned to Hashable type #1027

MapleCCC opened this issue Mar 10, 2021 · 3 comments
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version

Comments

@MapleCCC
Copy link

MapleCCC commented Mar 10, 2021

Environment data

  • Language Server version: 2021.2.3
  • OS and version: Windows 18363.1316
  • Python version: vanilla CPython 3.9.0

Expected behaviour

In Python, function is hashable. Given that obj is a function, the expression isinstance(obj, collections.abc.Hashable) evaluates to True.

Actual behaviour

Pylance reports that function cannot be assigned to type "Hashable".

Code Snippet / Additional information

from collections.abc import Hashable

def calculate_hash(obj: Hashable) -> int:
    return hash(obj)

def increment(x: int) -> int:
    return x + 1

# this statement prints True to the console
print(isinstance(increment, Hashable))

# this statement causes Pylance to report error
calculate_hash(increment)

image
image

@erictraut
Copy link
Contributor

Thanks for the bug report. This will be fixed in the next release.

@erictraut erictraut added bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version and removed triage labels Mar 10, 2021
@jakebailey
Copy link
Member

This issue has been fixed in version 2021.3.1, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/main/CHANGELOG.md#202131-10-march-2021

@MapleCCC
Copy link
Author

Thanks for your speed work and kind reply. I install the new version and the problem is resolved perfectly. I will close the issue then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working fixed in next version (main) A fix has been implemented and will appear in an upcoming version
Projects
None yet
Development

No branches or pull requests

3 participants