Skip to content

Commit 87e204c

Browse files
committed
Address review comments
1 parent ac20f26 commit 87e204c

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

src/runtime/modules/BuiltinsModule.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ PyResult<PyObject *> print(const PyTuple *args, const PyDict *kwargs, Interprete
114114
if (auto it = kwargs->map().find(file_keyword); it != kwargs->map().end()) {
115115
auto file_ = PyObject::from(it->second);
116116
if (file_.is_err()) { return file_; }
117-
file = file_.unwrap();
117+
if (file_.unwrap() != py_none()) { file = file_.unwrap(); }
118118
}
119119
if (auto it = kwargs->map().find(flush_keyword); it != kwargs->map().end()) {
120120
auto flush_ = PyObject::from(it->second);

src/runtime/modules/IOModule.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -990,10 +990,15 @@ struct Buffered
990990
{
991991
if (auto err = check_initialized(); err.is_err()) return Err(err.unwrap_err());
992992

993-
if (n < -1) { return Err(value_error("read length must be non-negative or -1")); }
993+
if (n < 0) {
994+
// TODO: determine actual buffer size
995+
n = 4096;
996+
}
994997

995998
if (is_closed()) { return Err(value_error("read of closed file")); }
996999

1000+
if (n == 0) { return PyBytes::create(); }
1001+
9971002
const auto have = readahead();
9981003
if (have > 0) { return static_cast<T *>(this)->readfast(n); }
9991004
Bytes b;
@@ -3133,7 +3138,12 @@ class TextIOWrapper : public TextIOBase
31333138
while (!m_buffer_bytes.has_value() || m_buffer_bytes->b.empty()) {
31343139
auto chunk = read_chunk(0);
31353140
if (chunk.is_err()) { return Err(chunk.unwrap_err()); }
3136-
if (chunk.unwrap() == 0) { break; }
3141+
if (!chunk.unwrap()) { break; }
3142+
}
3143+
3144+
if (!m_buffer_bytes.has_value()) {
3145+
// EOF
3146+
return PyString::create("");
31373147
}
31383148

31393149
std::string_view remaining{ bit_cast<const char *>(m_buffer_bytes->b.data()) + m_position,

0 commit comments

Comments
 (0)