[pypy-commit] pypy py3.5: Merged in thisch/pypy/py3.5 (pull request #584)

rlamy pypy.commits at gmail.com
Wed Nov 15 10:17:22 EST 2017


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: py3.5
Changeset: r93042:dfff7758834e
Date: 2017-11-15 15:16 +0000
http://bitbucket.org/pypy/pypy/changeset/dfff7758834e/

Log:	Merged in thisch/pypy/py3.5 (pull request #584)

	Change return type of os.times to posix.times_result

diff --git a/pypy/module/posix/__init__.py b/pypy/module/posix/__init__.py
--- a/pypy/module/posix/__init__.py
+++ b/pypy/module/posix/__init__.py
@@ -18,6 +18,7 @@
         'error': 'app_posix.error',
         'stat_result': 'app_posix.stat_result',
         'statvfs_result': 'app_posix.statvfs_result',
+        'times_result': 'app_posix.times_result',
         'uname_result': 'app_posix.uname_result',
         'urandom': 'app_posix.urandom',
         'terminal_size': 'app_posix.terminal_size',
diff --git a/pypy/module/posix/app_posix.py b/pypy/module/posix/app_posix.py
--- a/pypy/module/posix/app_posix.py
+++ b/pypy/module/posix/app_posix.py
@@ -122,6 +122,19 @@
 else:
     _validate_fd = validate_fd
 
+
+class times_result(metaclass=structseqtype):
+
+    name = "posix.times_result"
+    __module__ = "posix"
+
+    user = structseqfield(0, "user time")
+    system = structseqfield(1, "system time")
+    children_user = structseqfield(2, "user time of children")
+    children_system = structseqfield(3, "system time of children")
+    elapsed = structseqfield(4, "elapsed time since an arbitray point in the past")
+
+
 if osname == 'posix':
     def wait():
         """ wait() -> (pid, status)
diff --git a/pypy/module/posix/interp_posix.py b/pypy/module/posix/interp_posix.py
--- a/pypy/module/posix/interp_posix.py
+++ b/pypy/module/posix/interp_posix.py
@@ -684,11 +684,17 @@
     except OSError as e:
         raise wrap_oserror(space, e, eintr_retry=False)
     else:
-        return space.newtuple([space.newfloat(times[0]),
-                               space.newfloat(times[1]),
-                               space.newfloat(times[2]),
-                               space.newfloat(times[3]),
-                               space.newfloat(times[4])])
+        w_keywords = space.newdict()
+        w_tuple = space.newtuple([space.newfloat(times[0]),
+                                  space.newfloat(times[1]),
+                                  space.newfloat(times[2]),
+                                  space.newfloat(times[3]),
+                                  space.newfloat(times[4])])
+
+        w_times_result = space.getattr(space.getbuiltinmodule(os.name),
+                                       space.newtext('times_result'))
+        return space.call_function(w_times_result, w_tuple, w_keywords)
+
 
 @unwrap_spec(command='fsencode')
 def system(space, command):
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -378,16 +378,21 @@
 
     def test_times(self):
         """
-        posix.times() should return a five-tuple giving float-representations
-        (seconds, effectively) of the four fields from the underlying struct
-        tms and the return value.
+        posix.times() should return a posix.times_result object giving 
+        float-representations (seconds, effectively) of the four fields from 
+        the underlying struct tms and the return value.
         """
         result = self.posix.times()
-        assert isinstance(result, tuple)
+        assert isinstance(self.posix.times(), self.posix.times_result)
+        assert isinstance(self.posix.times(), tuple)
         assert len(result) == 5
         for value in result:
             assert isinstance(value, float)
-
+        assert isinstance(result.user, float)
+        assert isinstance(result.system, float)
+        assert isinstance(result.children_user, float)
+        assert isinstance(result.children_system, float)
+        assert isinstance(result.elapsed, float)
 
     def test_strerror(self):
         assert isinstance(self.posix.strerror(0), str)


More information about the pypy-commit mailing list