[pypy-commit] pypy py3.5-scandir: DirEntry.__repr__()
arigo
pypy.commits at gmail.com
Mon Aug 29 11:30:40 EDT 2016
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5-scandir
Changeset: r86706:1f468263bbc2
Date: 2016-08-29 17:29 +0200
http://bitbucket.org/pypy/pypy/changeset/1f468263bbc2/
Log: DirEntry.__repr__()
diff --git a/pypy/module/posix/interp_scandir.py b/pypy/module/posix/interp_scandir.py
--- a/pypy/module/posix/interp_scandir.py
+++ b/pypy/module/posix/interp_scandir.py
@@ -136,6 +136,10 @@
w_name = self.space.fsdecode(w_name)
self.w_name = w_name
+ def descr_repr(self, space):
+ u = space.unicode_w(space.repr(self.w_name))
+ return space.wrap(u"<DirEntry %s>" % u)
+
def fget_name(self, space):
return self.w_name
@@ -289,6 +293,7 @@
W_DirEntry.typedef = TypeDef(
'posix.DirEntry',
+ __repr__ = interp2app(W_DirEntry.descr_repr),
name = GetSetProperty(W_DirEntry.fget_name,
doc="the entry's base filename, relative to "
'scandir() "path" argument'),
diff --git a/pypy/module/posix/test/test_scandir.py b/pypy/module/posix/test/test_scandir.py
--- a/pypy/module/posix/test/test_scandir.py
+++ b/pypy/module/posix/test/test_scandir.py
@@ -164,3 +164,8 @@
assert d.name == 'file1'
ino = d.inode()
assert ino == d.stat().st_ino
+
+ def test_repr(self):
+ posix = self.posix
+ d = next(posix.scandir(self.dir1))
+ assert repr(d) == "<DirEntry 'file1'>"
More information about the pypy-commit
mailing list