On Sat, Jul 28, 2018 at 8:07 PM, Steven D'Aprano
wrote:
> On Sat, 28 Jul 2018 09:47:07 +, Gilmeh Serda wrote:
>
>> On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote:
>>
>>> I'm trying to get away from things like:
>>>
>>> >>> type(thing) is type(None)
>>
>> How about:
>>
>> >>>
On Sat, 28 Jul 2018 09:47:07 +, Gilmeh Serda wrote:
> On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote:
>
>> I'm trying to get away from things like:
>>
>> >>> type(thing) is type(None)
>
> How about:
>
> >>> some_thing = None
> >>> type(some_thing).__str__(some_thing)
>
On Thu, Jul 26, 2018, 10:00 AM Stephan Houben
wrote:
> Op 2018-07-25, Ian Kelly schreef :
>
> > Is there a reason for using singledispatch here rather than a simpler and
> > more readable "if color is None" check?
>
> Yes, the other 20 cases I didn't show.
> And extensibility.
>
That seems like
Op 2018-07-25, Ian Kelly schreef :
> Is there a reason for using singledispatch here rather than a simpler and
> more readable "if color is None" check?
Yes, the other 20 cases I didn't show.
And extensibility.
Stephan
--
https://mail.python.org/mailman/listinfo/python-list
Steven D'Aprano :
> On Wed, 25 Jul 2018 16:14:18 +, Schachner, Joseph wrote:
>> thing is None looks just as odd to me. Why not thing == None ? That
>> works.
>
> It is wrong (in other words, it doesn't work) because it allows
> non-None objects to masquerade as None and pretend to be what they
On Wed, 25 Jul 2018 16:14:18 +, Schachner, Joseph wrote:
> While I appreciate that use of "is" in thing is None, I claim this
> relies on knowledge of how Python works internally, to know that every
> None actually is the same ID (the same object) - it is singular.
No, it isn't knowledge
On Wed, Jul 25, 2018, 8:27 AM Stephan Houben
wrote:
> Op 2018-07-24, Chris Angelico schreef :
> > On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi
> > wrote:
> >> On 07/24/2018 01:07 PM, Chris Angelico wrote:
> >> I suppose one valid usage would be this sort of thing:
> >>
> >> fn = {
> >> int:
On Thu, Jul 26, 2018 at 12:20 AM, Stephan Houben
wrote:
> Op 2018-07-24, Chris Angelico schreef :
>> On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi
>> wrote:
>>> On 07/24/2018 01:07 PM, Chris Angelico wrote:
>>> I suppose one valid usage would be this sort of thing:
>>>
>>> fn = {
>>> int:
On Thu, Jul 26, 2018 at 2:14 AM, Schachner, Joseph
wrote:
> While I appreciate that use of "is" in thing is None, I claim this relies
> on knowledge of how Python works internally, to know that every None actually
> is the same ID (the same object) - it is singular.
That's part of the
While I appreciate that use of "is" in thing is None, I claim this relies on
knowledge of how Python works internally, to know that every None actually is
the same ID (the same object) - it is singular. That probably works for 0 and
1 also but you probably wouldn't consider testing thing
Op 2018-07-24, Chris Angelico schreef :
> On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi
> wrote:
>> On 07/24/2018 01:07 PM, Chris Angelico wrote:
>> I suppose one valid usage would be this sort of thing:
>>
>> fn = {
>> int: dispatchInt,
>> str: dispatchStr,
>> list: dispatchList,
>>
On Wed, Jul 25, 2018 at 9:18 AM, Rob Gaddi
wrote:
> On 07/24/2018 01:07 PM, Chris Angelico wrote:
>>
>> On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote:
>>>
>>> Consider:
>>>
>>> >>> type({}) is dict
>>> True
>>> >>> type(3) is int
>>> True
>>> >>>
On 07/24/2018 01:07 PM, Chris Angelico wrote:
On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote:
Consider:
>>> type({}) is dict
True
>>> type(3) is int
True
>>> type(None) is None
False
Obvious I guess, since the type object is not None.
So
On Tue, 24 Jul 2018 12:33:27 -0700, Tobiah wrote:
[...]
> So what would I compare type(None) to?
Why would you need to? The fastest, easiest, most reliable way to check
if something is None is:
if something is None
> >>> type(None)
>
> >>> type(None) is NoneType
>
https://docs.python.org/3.7/library/constants.html
"None
The sole value of the type NoneType..."
"x is None" and "type(x) is type(None)" are equivalent because of that.
I think though that the better way to do the first tests would be to use
isinstance
On Wed, Jul 25, 2018 at 5:33 AM, Tobiah wrote:
> Consider:
>
> >>> type({}) is dict
> True
> >>> type(3) is int
> True
> >>> type(None) is None
> False
>
> Obvious I guess, since the type object is not None.
> So what would I compare type(None) to?
In Python 2, you can import NoneType from types module.
In Python 3, the best you can do is:
NoneType = type(None)
Iwo Herka
https://github.com/IwoHerka
‐‐‐ Original Message ‐‐‐
On 24 July 2018 7:33 PM, Tobiah wrote:
>
>
> Consider:
>
> >>> type({}) is dict
>
> True
17 matches
Mail list logo