From 81f6beda9e9131983ae17c05f1d83f733e84896a Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Wed, 3 May 2023 16:30:37 +0200 Subject: [PATCH] Document sys.std* typing (#10135) --- stdlib/sys.pyi | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/stdlib/sys.pyi b/stdlib/sys.pyi index 786db72c7..c2fdbeccc 100644 --- a/stdlib/sys.pyi +++ b/stdlib/sys.pyi @@ -57,9 +57,20 @@ if sys.version_info >= (3, 8): pycache_prefix: str | None ps1: object ps2: object + +# TextIO is used instead of more specific types for the standard streams, +# since they are often monkeypatched at runtime. At startup, the objects +# are initialized to instances of TextIOWrapper. +# +# To use methods from TextIOWrapper, use an isinstance check to ensure that +# the streams have not been overridden: +# +# if isinstance(sys.stdout, io.TextIOWrapper): +# sys.stdout.reconfigure(...) stdin: TextIO stdout: TextIO stderr: TextIO + if sys.version_info >= (3, 10): stdlib_module_names: frozenset[str]