summaryrefslogtreecommitdiff
path: root/tests/basics/special_methods2.py
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-10 23:10:46 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-10 23:14:23 +1000
commit3678a6bdc6a925f2bce6423c41f911229836f946 (patch)
tree954bd10aefdaf95a238a7a8b6d11cf46dfee542d /tests/basics/special_methods2.py
parent29d28c2574d6c0b93fd3fc869b389a61dee12102 (diff)
py/modbuiltins: Make built-in dir support the __dir__ special method.
If MICROPY_PY_ALL_SPECIAL_METHODS is enabled then dir() will now delegate to the special method __dir__ if the object it is listing has this method.
Diffstat (limited to 'tests/basics/special_methods2.py')
-rw-r--r--tests/basics/special_methods2.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/basics/special_methods2.py b/tests/basics/special_methods2.py
index ba7cf27cd..1a38a250c 100644
--- a/tests/basics/special_methods2.py
+++ b/tests/basics/special_methods2.py
@@ -94,6 +94,9 @@ class Cud():
print("__isub__ called")
return self
+ def __dir__(self):
+ return ['a', 'b', 'c']
+
cud1 = Cud()
cud2 = Cud()
@@ -113,6 +116,12 @@ cud2 // cud1
cud1 += cud2
cud1 -= cud2
+# test that dir() delegates to __dir__ special method
+print(dir(cud1))
+
+# test that dir() does not delegate to __dir__ for the type
+print('a' in dir(Cud))
+
# TODO: the following operations are not supported on every ports
#
# ne is not supported, !(eq) is called instead