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]