diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-11 03:16:04 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-11 03:33:19 +0300 |
commit | ea9708092e8a49377a465ef8c8500943fe9ba772 (patch) | |
tree | 90e5dd9cf1ab38518df12410225b9f4c94066e45 /tests/basics/subclass_native_cmp.py | |
parent | 9511f60f016547ab00f634d451c230351bd8b225 (diff) | |
download | micropython-ea9708092e8a49377a465ef8c8500943fe9ba772.tar.gz micropython-ea9708092e8a49377a465ef8c8500943fe9ba772.zip |
objtuple: Go out of the way to support comparison of subclasses.
Two things are handled here: allow to compare native subtypes of tuple,
e.g. namedtuple (TODO: should compare type too, currently compared
duck-typedly by content). Secondly, allow user sunclasses of tuples
(and its subtypes) be compared either. "Magic" I did previously in
objtype.c covers only one argument (lhs is many), so we're in trouble
when lhs is native type - there's no other option besides handling
rhs in special manner. Fortunately, this patch outlines approach with
fast path for native types.
Diffstat (limited to 'tests/basics/subclass_native_cmp.py')
-rw-r--r-- | tests/basics/subclass_native_cmp.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/basics/subclass_native_cmp.py b/tests/basics/subclass_native_cmp.py new file mode 100644 index 0000000000..1a095bfa1a --- /dev/null +++ b/tests/basics/subclass_native_cmp.py @@ -0,0 +1,9 @@ +# Test calling non-special method inherited from native type + +class mytuple(tuple): + pass + +t = mytuple((1, 2, 3)) +print(t) +print(t == (1, 2, 3)) +print((1, 2, 3) == t) |