Typing and Generics
typing.TextIO
Specializes the typing IO interface for text streams. Reading and writing operate on strings; choose an explicit encoding for real text files. It is not a runtime structural protocol.
Formal Syntax & Structure
python syntaxpython
typing.TextIOReturn Value
type expression
Typing construct or runtime result as described; static typing rules are not runtime validation.
Working Example
Example Snippetpython
from typing import TextIO
import iodef read_line(stream:TextIO)->str: return stream.readline().rstrip('\n')with io.StringIO('one\ntwo') as stream: result=read_line(stream)print(result)