Created
April 8, 2022 03:53
-
-
Save moskytw/4cb444429fb6f86e1d2bb72c996fe240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import List | |
# Collection is Sized, Iterable, Container (supports __contains__) | |
from collections.abc import Sequence, Collection | |
def accept_list(x: list) -> None: | |
pass | |
def accept_caped_list(x: List) -> None: | |
pass | |
def accept_sequence(x: Sequence) -> None: | |
pass | |
def accept_collection(x: Collection) -> None: | |
pass | |
accept_list([1, 2, 3]) | |
accept_list((1, 2, 3)) # -> mypy: error: incompatible type | |
accept_list({}.keys()) # -> mypy: error: incompatible type | |
accept_caped_list([1, 2, 3]) | |
accept_caped_list((1, 2, 3)) # -> mypy: error: incompatible type | |
accept_caped_list({}.keys()) # -> mypy: error: incompatible type | |
accept_sequence([1, 2, 3]) | |
accept_sequence((1, 2, 3)) | |
accept_sequence({}.keys()) # -> mypy: error: incompatible type | |
accept_collection([1, 2, 3]) | |
accept_collection((1, 2, 3)) | |
accept_collection({}.keys()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment