On this page
typing.Collection
Prev: typing.clear_overloads | Up: typing | Next: typing.Concatenate
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.Collection
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import Collection
Signature & Overview
typing.Collection(*args, **kwargs)
Deprecated alias to collections.abc.Collection.
Usage
from typing import Collection
def is_nonempty(items: Collection[int]) -> bool:
return len(items) > 0
assert is_nonempty([1, 2]) and is_nonempty({1})
Gotchas
- Prefer
collections.abc.Collection[T]in Python 3.9+: CombinesSized,Iterable, andContainer(len(),for,in).
REPL Inspect
from typing import Collection
help(Collection)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/clear_overloads Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Concatenate Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/typing/AbstractSet Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Annotated Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/Any Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_never Linked here; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/assert_type shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncContextManager shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/AsyncGenerator shared tags: #stdlib, #typing