Re: Checking whether type is None

2018-07-28 Thread Chris Angelico
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: >> >> >>>

Re: Checking whether type is None

2018-07-28 Thread Steven D'Aprano
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) >

Re: Checking whether type is None

2018-07-27 Thread Ian Kelly
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

Re: Checking whether type is None

2018-07-26 Thread Stephan Houben
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

Re: Checking whether type is None

2018-07-26 Thread Marko Rauhamaa
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

Re: Checking whether type is None

2018-07-25 Thread Steven D'Aprano
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

Re: Checking whether type is None

2018-07-25 Thread Ian Kelly
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:

Re: Checking whether type is None

2018-07-25 Thread Chris Angelico
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:

Re: Checking whether type is None

2018-07-25 Thread Chris Angelico
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

RE: Checking whether type is None

2018-07-25 Thread Schachner, Joseph
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

Re: Checking whether type is None

2018-07-25 Thread Stephan Houben
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, >>

Re: Checking whether type is None

2018-07-24 Thread Chris Angelico
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 >>> >>>

Re: Checking whether type is None

2018-07-24 Thread Rob Gaddi
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

Re: Checking whether type is None

2018-07-24 Thread Steven D'Aprano
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 >

RE: Checking whether type is None

2018-07-24 Thread David Raymond
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

Re: Checking whether type is None

2018-07-24 Thread Chris Angelico
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?

Re: Checking whether type is None

2018-07-24 Thread Iwo Herka
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