Skip to content

None cannot be assigned to typing.Hashable #985

Closed
@layday

Description

@layday

Describe the bug
None cannot be assigned to typing.Hashable. None is hashable in Python.

To Reproduce
Type check the snippet below.

Expected behavior
That None would be accepted as a value of type Hashable.

Screenshots or Code

from typing import Dict, Hashable

# Expression of type "None" cannot be assigned to declared type "Hashable"
#   Type "None" cannot be assigned to type "Hashable"
foo: Hashable = None

# Expression of type "dict[None, str]" cannot be assigned to declared type "Dict"
#   TypeVar "_KT" is invariant
#     Type "None" cannot be assigned to type "Hashable"
bar: Dict[Hashable, str] = {None: ''}

# True
isinstance(None, Hashable)

VS Code extension or command-line
Extension, 1.1.65

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions