On this page
typing.SupportsBytes
Prev: typing.SupportsAbs | Up: typing | Next: typing.SupportsComplex
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.SupportsBytes
Tags: #public #python3 #stdlib #typing
Import
import typing
from typing import SupportsBytes
Signature & Overview
typing.SupportsBytes(*args, **kwargs)
A protocol with one abstract method bytes.
Usage
from typing import SupportsBytes
class Token:
def __bytes__(self) -> bytes: return b"tok"
assert isinstance(Token(), SupportsBytes) and bytes(Token()) == b"tok"
Gotchas
- Matches objects implementing
__bytes__(): Note thatstrdoes not implement__bytes__.
REPL Inspect
from typing import SupportsBytes
help(SupportsBytes)
Linked from
Related notes
- tuts/python3/stdlib_module/typing/SupportsAbs Linked here; links to this page; shared tags: #stdlib, #typing
- tuts/python3/stdlib_module/typing/SupportsComplex 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