On this page
  1. typing.SupportsBytes
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from typing import SupportsBytes
help(SupportsBytes)

Linked from

Related notes