Typing and Generics
typing.BinaryIO
Describes streams whose read and write operations use bytes. Use binary mode for files containing raw data, and decode bytes explicitly when text is intended. It is a typing interface, not a runtime validator.
Formal Syntax & Structure
python syntaxpython
typing.BinaryIOReturn Value
type expression
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import BinaryIO
import iodef header(stream:BinaryIO)->bytes: return stream.read(2)with io.BytesIO(b'ABCD') as stream: result=header(stream)print(result)