[Python-ideas] `numbers.Natural`

Ram Rachum ram at rachum.com
Fri Sep 26 20:37:39 CEST 2014


I checked it and you're right. So I guess `Hashable` is a bit confusing:

    >>> isinstance(([3],), collections.Hashable)
    True

On Fri, Sep 26, 2014 at 9:35 PM, Andrew Barnert <abarnert at yahoo.com> wrote:

> On Sep 26, 2014, at 11:13, Ram Rachum <ram at rachum.com> wrote:
>
> I agree with both the points you raised, they're both disadvantages. The
> question is whether the uses would be worth these two disadvantages.
> (`collections.Hashable` also has the second disadvantage you mentioned, and
> it's still in the stdlib, so there's hope.)
>
>
> Hashable doesn't have that disadvantage. It checks whether the object's
> class or any superclass has a __hash__ method. So it's still based on the
> type, not on the value, and it works as expected with issubclass.
>
>
> On Fri, Sep 26, 2014 at 9:10 PM, Thomas Gläßle <t_glaessle at gmx.de> wrote:
>
>>  At first glance it sounds nice and straight forward.
>> But - is a natural positive, or just non-negative? I guess, I'd have to
>> look it up in the docs each time, since either definition is used in lots
>> of places.
>> Also, Natural does not correspond to the python type, but its value. So,
>> you couldn't use it with issubclass.
>>
>>
>> Ram Rachum wrote on 09/26/2014 07:54 PM:
>>
>> I wish the `numbers` module would include a `Natural` class that would
>> simply check whether the number is integral and positive.
>>
>>
>> _______________________________________________
>> Python-ideas mailing listPython-ideas at python.orghttps://mail.python.org/mailman/listinfo/python-ideas
>> Code of Conduct: http://python.org/psf/codeofconduct/
>>
>>
>>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140926/b7becf9a/attachment.html>


More information about the Python-ideas mailing list