Author: Armin Rigo <[email protected]>
Branch: 
Changeset: r97036:cd5ae5acffdd
Date: 2019-07-30 18:22 +0000
http://bitbucket.org/pypy/pypy/changeset/cd5ae5acffdd/

Log:    Merged in Bystroushaak/pypy/feature_closed_prop_to_rfile (pull
        request #649)

        RFile; added property .closed to mirror standard `file` behaviour.

diff --git a/rpython/rlib/rfile.py b/rpython/rlib/rfile.py
--- a/rpython/rlib/rfile.py
+++ b/rpython/rlib/rfile.py
@@ -312,6 +312,10 @@
         if not self._ll_file:
             raise ValueError("I/O operation on closed file")
 
+    @property
+    def closed(self):
+        return not self._ll_file
+
     def _fread(self, buf, n, stream):
         if not self._univ_newline:
             return c_fread(buf, 1, n, stream)
diff --git a/rpython/rlib/test/test_rfile.py b/rpython/rlib/test/test_rfile.py
--- a/rpython/rlib/test/test_rfile.py
+++ b/rpython/rlib/test/test_rfile.py
@@ -411,7 +411,10 @@
         def f():
             with open(fname, "w") as f:
                 f.write("dupa")
+                assert not f.closed
+
             try:
+                assert f.closed
                 f.write("dupb")
             except ValueError:
                 pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to