Skip to content

Instantly share code, notes, and snippets.

@moskytw
Created April 8, 2022 03:53
Show Gist options
  • Save moskytw/4cb444429fb6f86e1d2bb72c996fe240 to your computer and use it in GitHub Desktop.
Save moskytw/4cb444429fb6f86e1d2bb72c996fe240 to your computer and use it in GitHub Desktop.
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