Strict comparisons in Python 2

Ian Kelly ian.g.kelly at gmail.com
Tue Oct 13 09:58:27 EDT 2015


On Oct 13, 2015 7:48 AM, "Steven D'Aprano" <steve at pearwood.info> wrote:
>
> In Python 3, comparisons between arbitrary types raise TypeError:
>
> py> None < 2
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: unorderable types: NoneType() < int()
>
>
> In Python 2, that same comparison will arbitrarily return True or False,
> according to some implementation-dependent rule.
>
> Is there some way to force the Python 3 rules into Python 2? Something
like
> a __future__ import?

You couldn't do this with a __future__ import because those must be
confined to the importing module and are therefore generally limited to
syntax changes. It may be a good candidate for the six library, but I don't
see any existing support there for it.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20151013/1ba2a203/attachment.html>


More information about the Python-list mailing list