From ea9708092e8a49377a465ef8c8500943fe9ba772 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 11 May 2014 03:16:04 +0300 Subject: 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. --- tests/basics/subclass_native_cmp.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 tests/basics/subclass_native_cmp.py (limited to 'tests/basics/subclass_native_cmp.py') diff --git a/tests/basics/subclass_native_cmp.py b/tests/basics/subclass_native_cmp.py new file mode 100644 index 000000000..1a095bfa1 --- /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) -- cgit v1.2.3