diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index 454638e299..f5af543254 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -3548,6 +3548,10 @@ PYBIND11_NOINLINE void print(const tuple &args, const dict &kwargs) { } } + if (file.is_none()) { + return; + } + auto write = file.attr("write"); write(std::move(line)); write(kwargs.contains("end") ? kwargs["end"] : str("\n"));