Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit48d4c22

Browse files
committed
Update fileinput to CPython 3.11.5
1 parent9031a0a commit48d4c22

File tree

2 files changed

+8
-82
lines changed

2 files changed

+8
-82
lines changed

‎Lib/fileinput.py‎

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,10 @@ def __init__(self, files=None, inplace=False, backup="", *,
217217
EncodingWarning,2)
218218

219219
# restrict mode argument to reading modes
220-
ifmodenotin ('r','rU','U','rb'):
221-
raiseValueError("FileInput opening mode must be one of "
222-
"'r', 'rU', 'U' and 'rb'")
223-
if'U'inmode:
224-
importwarnings
225-
warnings.warn("'U' mode is deprecated",
226-
DeprecationWarning,2)
220+
ifmodenotin ('r','rb'):
221+
raiseValueError("FileInput opening mode must be 'r' or 'rb'")
227222
self._mode=mode
228-
self._write_mode=mode.replace('r','w')if'U'notinmodeelse'w'
223+
self._write_mode=mode.replace('r','w')
229224
ifopenhook:
230225
ifinplace:
231226
raiseValueError("FileInput cannot use an opening hook in inplace mode")
@@ -262,21 +257,6 @@ def __next__(self):
262257
self.nextfile()
263258
# repeat with next file
264259

265-
def__getitem__(self,i):
266-
importwarnings
267-
warnings.warn(
268-
"Support for indexing FileInput objects is deprecated. "
269-
"Use iterator protocol instead.",
270-
DeprecationWarning,
271-
stacklevel=2
272-
)
273-
ifi!=self.lineno():
274-
raiseRuntimeError("accessing lines out of order")
275-
try:
276-
returnself.__next__()
277-
exceptStopIteration:
278-
raiseIndexError("end of input reached")
279-
280260
defnextfile(self):
281261
savestdout=self._savestdout
282262
self._savestdout=None

‎Lib/test/test_fileinput.py‎

Lines changed: 5 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
fromtest.support.os_helperimportTESTFN
3030
fromtest.support.os_helperimportunlinkassafe_unlink
3131
fromtest.supportimportos_helper
32-
fromtest.supportimportwarnings_helper
3332
fromtestimportsupport
3433
fromunittestimportmock
3534

@@ -230,22 +229,11 @@ def test_fileno(self):
230229
line=list(fi)
231230
self.assertEqual(fi.fileno(),-1)
232231

233-
# TODO: RUSTPYTHON
234-
@unittest.expectedFailure
235-
deftest_opening_mode(self):
236-
try:
237-
# invalid mode, should raise ValueError
238-
fi=FileInput(mode="w",encoding="utf-8")
239-
self.fail("FileInput should reject invalid mode argument")
240-
exceptValueError:
241-
pass
242-
# try opening in universal newline mode
243-
t1=self.writeTmp(b"A\nB\r\nC\rD",mode="wb")
244-
withwarnings_helper.check_warnings(('',DeprecationWarning)):
245-
fi=FileInput(files=t1,mode="U",encoding="utf-8")
246-
withwarnings_helper.check_warnings(('',DeprecationWarning)):
247-
lines=list(fi)
248-
self.assertEqual(lines, ["A\n","B\n","C\n","D"])
232+
deftest_invalid_opening_mode(self):
233+
formodein ('w','rU','U'):
234+
withself.subTest(mode=mode):
235+
withself.assertRaises(ValueError):
236+
FileInput(mode=mode)
249237

250238
deftest_stdin_binary_mode(self):
251239
withmock.patch('sys.stdin')asm_stdin:
@@ -380,44 +368,6 @@ def test_empty_files_list_specified_to_constructor(self):
380368
withFileInput(files=[],encoding="utf-8")asfi:
381369
self.assertEqual(fi._files, ('-',))
382370

383-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
384-
deftest__getitem__(self):
385-
"""Tests invoking FileInput.__getitem__() with the current
386-
line number"""
387-
t=self.writeTmp("line1\nline2\n")
388-
withFileInput(files=[t],encoding="utf-8")asfi:
389-
retval1=fi[0]
390-
self.assertEqual(retval1,"line1\n")
391-
retval2=fi[1]
392-
self.assertEqual(retval2,"line2\n")
393-
394-
deftest__getitem___deprecation(self):
395-
t=self.writeTmp("line1\nline2\n")
396-
withself.assertWarnsRegex(DeprecationWarning,
397-
r'Use iterator protocol instead'):
398-
withFileInput(files=[t])asfi:
399-
self.assertEqual(fi[0],"line1\n")
400-
401-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
402-
deftest__getitem__invalid_key(self):
403-
"""Tests invoking FileInput.__getitem__() with an index unequal to
404-
the line number"""
405-
t=self.writeTmp("line1\nline2\n")
406-
withFileInput(files=[t],encoding="utf-8")asfi:
407-
withself.assertRaises(RuntimeError)ascm:
408-
fi[1]
409-
self.assertEqual(cm.exception.args, ("accessing lines out of order",))
410-
411-
@warnings_helper.ignore_warnings(category=DeprecationWarning)
412-
deftest__getitem__eof(self):
413-
"""Tests invoking FileInput.__getitem__() with the line number but at
414-
end-of-input"""
415-
t=self.writeTmp('')
416-
withFileInput(files=[t],encoding="utf-8")asfi:
417-
withself.assertRaises(IndexError)ascm:
418-
fi[0]
419-
self.assertEqual(cm.exception.args, ("end of input reached",))
420-
421371
deftest_nextfile_oserror_deleting_backup(self):
422372
"""Tests invoking FileInput.nextfile() when the attempt to delete
423373
the backup file would raise OSError. This error is expected to be
@@ -1031,10 +981,6 @@ def check(mode, expected_lines):
1031981
self.assertEqual(lines,expected_lines)
1032982

1033983
check('r', ['A\n','B\n','C\n','D\u20ac'])
1034-
withself.assertWarns(DeprecationWarning):
1035-
check('rU', ['A\n','B\n','C\n','D\u20ac'])
1036-
withself.assertWarns(DeprecationWarning):
1037-
check('U', ['A\n','B\n','C\n','D\u20ac'])
1038984
withself.assertRaises(ValueError):
1039985
check('rb', ['A\n','B\r\n','C\r','D\u20ac'])
1040986

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp