On this page
  1. typing.BinaryIO
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

typing.BinaryIO

Prev: typing.Awaitable | Up: typing | Next: typing.ByteString
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.BinaryIO
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import BinaryIO

Signature & Overview

typing.BinaryIO()

Typed approximation of the return of open() in binary mode.

Methods & Attributes

Usage

import io
from typing import BinaryIO

def read_header(fh: BinaryIO) -> bytes:
    return fh.read(4)

assert read_header(io.BytesIO(b"PNG\r\n")) == b"PNG\r"

Gotchas

REPL Inspect

from typing import BinaryIO
help(BinaryIO)

Linked from

Related notes