Skip to content

Commit fc3436b

Browse files
committed
Add an encoding property to TextIOBase instances.
Add sys.__std{in,out,err}__. Make test_sys pass.
1 parent 75d6f1a commit fc3436b

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Lib/io.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,6 +925,11 @@ def __next__(self) -> str:
925925
raise StopIteration
926926
return line
927927

928+
@property
929+
def encoding(self):
930+
"""Subclasses should override."""
931+
return None
932+
928933
# The following are provided for backwards compatibility
929934

930935
def readlines(self, hint=None):
@@ -970,6 +975,10 @@ def __init__(self, buffer, encoding=None, newline=None):
970975
self._snapshot = None
971976
self._seekable = self._telling = self.buffer.seekable()
972977

978+
@property
979+
def encoding(self):
980+
return self._encoding
981+
973982
# A word about _snapshot. This attribute is either None, or a
974983
# tuple (decoder_state, readahead, pending) where decoder_state is
975984
# the second (integer) item of the decoder state, readahead is the

Lib/site.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,9 @@ class open:
411411
def __new__(cls, *args, **kwds):
412412
return io.open(*args, **kwds)
413413
__builtin__.open = open
414-
sys.stdin = io.open(0, "r")
415-
sys.stdout = io.open(1, "w")
416-
sys.stderr = io.open(2, "w")
414+
sys.__stdin__ = sys.stdin = io.open(0, "r")
415+
sys.__stdout__ = sys.stdout = io.open(1, "w")
416+
sys.__stderr__ = sys.stderr = io.open(2, "w")
417417

418418

419419
def main():

0 commit comments

Comments
 (0)