Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address comments by @corona10
  • Loading branch information
Gihwan Kim committed Feb 21, 2023
commit c81a2d1c9d74f11941a4cb277049acd203f67e92
4 changes: 1 addition & 3 deletions Lib/fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ def isstdin(self):


def hook_compressed(filename, mode, *, encoding=None, errors=None):
if encoding is None: # EncodingWarning is emitted in FileInput() already.
if encoding is None and "b" not in mode: # EncodingWarning is emitted in FileInput() already.
encoding = "locale"
ext = os.path.splitext(filename)[1]
if ext == '.gz':
Expand All @@ -409,8 +409,6 @@ def hook_compressed(filename, mode, *, encoding=None, errors=None):
import bz2
stream = bz2.BZ2File(filename, mode)
else:
if "b" in mode:
return open(filename, mode, errors=errors)
return open(filename, mode, encoding=encoding, errors=errors)

# gzip and bz2 are binary mode by default.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_fileinput.py
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ def do_test_use_builtin_open_binary(self, filename, mode):

self.assertEqual(self.fake_open.invocation_count, 1)
self.assertEqual(self.fake_open.last_invocation,
((filename, mode), {'errors': None}))
((filename, mode), {'encoding': None, 'errors': None}))

def do_test_use_builtin_open_text(self, filename, mode):
original_open = self.replace_builtin_open(self.fake_open)
Expand Down
2 changes: 1 addition & 1 deletion Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,7 @@ Tyler Kieft
Mads Kiilerich
Jason Killen
Derek D. Kim
Gihwan Kim
Jan Kim
Taek Joo Kim
Sam Kimbrel
Expand Down Expand Up @@ -1001,7 +1002,6 @@ Ilia Kurenkov
Vladimir Kushnir
Erno Kuusela
Kabir Kwatra
Gihwan Kim
Ross Lagerwall
Cameron Laird
Loïc Lajeanne
Expand Down