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

typing.TextIO

Prev: typing.Text | Up: typing | Next: typing.TypeAliasType
Rel: typing.AbstractSet, typing.Annotated, typing.Any, typing.assert_never
Ref: docs.python.org — typing.TextIO
Tags: #public #python3 #stdlib #typing


Import

import typing
from typing import TextIO

Signature & Overview

typing.TextIO()

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

Methods & Attributes

Usage

import io
from typing import TextIO

def first_line(fh: TextIO) -> str:
    return fh.readline().strip()

assert first_line(io.StringIO("hello\nworld")) == "hello"

Gotchas

REPL Inspect

from typing import TextIO
help(TextIO)

Linked from

Related notes