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

Commit4173474

Browse files
committed
Fix comments, better handle if write returuns a big/small int
1 parent947ff62 commit4173474

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

‎Modules/_io/textio.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1738,8 +1738,8 @@ _textiowrapper_writeflush(textio *self)
17381738

17391739
/* Try to determine bytes written from return value
17401740
1741-
XXX:On unexpectedreturn this matchesprevious behaviorand asumes
1742-
all data waswritten. */
1741+
XXX:Unexpectedreturn: matchprevious behaviorassume all data was
1742+
written. */
17431743
/* OPEN QUESTION: None is common in CPython, should this warn? */
17441744
if (ret==Py_None) {
17451745
Py_DECREF(b);
@@ -1762,34 +1762,29 @@ _textiowrapper_writeflush(textio *self)
17621762
/* Check for unexpected return values. */
17631763
/* Can't get out size follow return previous behavior. */
17641764
if (size==-1&&PyErr_Occurred()) {
1765-
if (!PyErr_ExceptionMatches(PyExc_TypeError)) {
1766-
Py_DECREF(b);
1767-
Py_DECREF(ret);
1768-
return-1;
1769-
}
1770-
PyErr_Clear();/* fall through */
1765+
/* Warn about the value, but do not error. */
1766+
PyObject*exc=PyErr_GetRaisedException()
17711767
PyErr_WarnFormat(PyExc_DeprecationWarning,1,
1772-
"buffer.write returned value '%s' not specified by"
1773-
" BufferedIOBase or TextIOBase",ret);
1768+
"write returned value '%s' not specified by"
1769+
" BufferedIOBase or TextIOBase (%s)",ret,exc);
1770+
Py_DECREF(exc);
17741771
Py_DECREF(b);
17751772
Py_DECREF(ret);
17761773
return0;
17771774
}
17781775
/* Negative count of bytes doesn't make sense. */
17791776
elseif (size<0) {
17801777
PyErr_WarnFormat(PyExc_RuntimeWarning,1,
1781-
"buffer.write returned negative count of bytes '%s'",
1782-
ret);
1778+
"write returned negative count of bytes '%s'",ret);
17831779
Py_DECREF(b);
17841780
Py_DECREF(ret);
17851781
return0;
17861782
}
17871783
/* More written than passed in call. */
17881784
elseif (size>bytes_to_write) {
17891785
PyErr_WarnFormat(PyExc_RuntimeWarning,1,
1790-
"buffer.write returned '%s' bytes written but was only"
1791-
" called with '%s' bytes to write",
1792-
ret,bytes_to_write);
1786+
"write returned '%s' bytes written but was only called"
1787+
" with '%s' bytes to write",ret,bytes_to_write);
17931788
Py_DECREF(b);
17941789
Py_DECREF(ret);
17951790
return0;
@@ -1805,7 +1800,7 @@ _textiowrapper_writeflush(textio *self)
18051800
break;
18061801
}
18071802

1808-
/* Make a newPyByte to keep type for next call to write. */
1803+
/* Make a newPyBytes to keep type for next call to write. */
18091804
pending=PyBytes_FromStringAndSize(
18101805
PyBytes_AS_STRING(b)+size,
18111806
self->pending_bytes_count);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp