Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Python 2.4 removes None data type?

Reply
Thread Tools

Python 2.4 removes None data type?

 
 
gaudetteje@gmail.com
Guest
Posts: n/a
 
      03-04-2005
I just read in the 'What's New in Python 2.4' document that the None
data type was converted to a constant:
http://python.org/doc/2.4/whatsnew/node15.html

"""
# None is now a constant; code that binds a new value to the name
"None" is now a syntax error.
"""

So, what's the implications of this? I find the lack of explanation a
little puzzling, since I've written code that compares a variable's
type with the 'None' type. For example, a variable would be
initialized to 'None' and if it went through a loop unchanged, I could
determine this at the end by using a conditional type(var) ==
type(None). What will type(None) return now?

 
Reply With Quote
 
 
 
 
Tim Peters
Guest
Posts: n/a
 
      03-04-2005
[(E-Mail Removed)]
> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html
>
> """
> # None is now a constant; code that binds a new value to the name
> "None" is now a syntax error.
> """
>
> So, what's the implications of this?


No implications, for any sane code. You can no longer do things like this:

>>> None = 2

SyntaxError: assignment to None

That's all.

> I find the lack of explanation a little puzzling, since I've written code that
> compares a variable's type with the 'None' type. For example, a variable
> would be initialized to 'None' and if it went through a loop unchanged, I could
> determine this at the end by using a conditional type(var) == type(None).


Python's None is a singleton, meaning that there is a single, unique
instance of type type(None). So in the case you describe, it's
correct, and idiomatic, to test

if var is None:

instead. Checking type(var) against type(None) will still work, but
was never the best way to do it.

If you have an expression like

var = None

that's fine. You're not changing the binding of name "None" there,
you're changing the binding of name "var".

> What will type(None) return now?


That hasn't changed:

>>> type(None)

<type 'NoneType'>
 
Reply With Quote
 
 
 
 
Gary D. Duzan
Guest
Posts: n/a
 
      03-04-2005
In article <(E-Mail Removed) .com>,
http://www.velocityreviews.com/forums/(E-Mail Removed) <(E-Mail Removed)> wrote:
>
>
>I just read in the 'What's New in Python 2.4' document that the None
>data type was converted to a constant:
>http://python.org/doc/2.4/whatsnew/node15.html
>
>"""
># None is now a constant; code that binds a new value to the name
>"None" is now a syntax error.
>"""
>
>So, what's the implications of this? I find the lack of explanation a
>little puzzling, since I've written code that compares a variable's
>type with the 'None' type. For example, a variable would be
>initialized to 'None' and if it went through a loop unchanged, I could
>determine this at the end by using a conditional type(var) ==
>type(None). What will type(None) return now?


Empirically, NoneType, same as before. The change you refer to is
to prevent the user from doing silly things like:

================================================== ========================
Python 2.3.4 (#1, Feb 8 2005, 13:07:40)
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(None)

<type 'NoneType'>
>>> None="fred"

<stdin>:1: SyntaxWarning: assignment to None
>>> None

'fred'
>>> type(None)

<type 'str'>
>>>

================================================== ========================
Python 2.4 (#1, Mar 4 2005, 16:55:16)
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type(None)

<type 'NoneType'>
>>> None="Fred"

SyntaxError: assignment to None
>>> type(None)

<type 'NoneType'>
>>>

================================================== ========================

So your idiom should still work. Note that since there is only
one NoneType instance (i.e. None), you can just test for "var is None"
and save yourself some work.

Gary Duzan
BBN Technologies


 
Reply With Quote
 
Warren Postma
Guest
Posts: n/a
 
      03-04-2005
(E-Mail Removed) wrote:

> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html


Implication: A long standing wart in Python now gone. Its time to
gloat. Are there any really evil glitches LEFT in Python? Now go look at
Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".


Warren
 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      03-04-2005
Warren Postma wrote:
> (E-Mail Removed) wrote:
>
>> I just read in the 'What's New in Python 2.4' document that the None
>> data type was converted to a constant:
>> http://python.org/doc/2.4/whatsnew/node15.html

>
>
> Implication: A long standing wart in Python now gone. Its time to
> gloat. Are there any really evil glitches LEFT in Python? Now go look at
> Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".
>
>

Remaining warts that won't disappear:

print >> file, stuff
@decorator

regards
Steve
--
Meet the Python developers and your c.l.py favorites March 23-25
Come to PyCon DC 2005 http://www.pycon.org/
Steve Holden http://www.holdenweb.com/
 
Reply With Quote
 
Michael Hoffman
Guest
Posts: n/a
 
      03-04-2005
Warren Postma wrote:

> Implication: A long standing wart in Python now gone. Its time to
> gloat. Are there any really evil glitches LEFT in Python? Now go look at
> Perl and come back and say "Thank-deity-of-my-choice-I'm-using-Python".


The fact that True and False are not constants?
--
Michael Hoffman
 
Reply With Quote
 
Roy Smith
Guest
Posts: n/a
 
      03-04-2005
In article <(E-Mail Removed) .com>,
"(E-Mail Removed)" <(E-Mail Removed)> wrote:

> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html
>
> """
> # None is now a constant; code that binds a new value to the name
> "None" is now a syntax error.
> """
>
> So, what's the implications of this? I find the lack of explanation a
> little puzzling, since I've written code that compares a variable's
> type with the 'None' type. For example, a variable would be
> initialized to 'None' and if it went through a loop unchanged, I could
> determine this at the end by using a conditional type(var) ==
> type(None). What will type(None) return now?


Just out of curiosity, *why* did you test against type(None). What did it
buy you compared to the simpler var == None'?

In any case, it looks like it does the right thing:

Python 2.4 (#1, Jan 17 2005, 14:59:14)
[GCC 3.3.3 (NetBSD nb3 20040520)] on netbsd2
Type "help", "copyright", "credits" or "license" for more information.
>>> type (None)

<type 'NoneType'>
 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      03-05-2005

(E-Mail Removed) wrote:
> I just read in the 'What's New in Python 2.4' document that the None
> data type was converted to a constant:
> http://python.org/doc/2.4/whatsnew/node15.html
>
> """
> # None is now a constant; code that binds a new value to the name
> "None" is now a syntax error.
> """
>
> So, what's the implications of this?


Relax. The sky is not falling.

> I find the lack of explanation a
> little puzzling, since I've written code that compares a variable's
> type with the 'None' type.


It is saying that if you had been silly enough to do

None = "fubar"

you will now get a syntax error.

It said absolutely nothing about "removes None data type".

There are (at least) two possible reasons for a lack of explanation:

(1) Python is one of those expensive software products that hit you
with "upgrades" where you have difficulty finding about the changes in
advance (let alone participarting in the design process) and require
you to recode large chunks of your application but you can't find out
with any sort of precision the necessary changes might be from the
vague descriptions on a complex and ever-changing website.

(2) Unless you have done something completely idiotic [which the change
is designed to prevent], no change is required to your code. OR, like
for the changes to integer division, the change is announced for a
future version, you can do "from __future__ inport whatever". Any
furore (and there have been some doozies) noticeable in the newsgroup
is part of the design process, and has died down well before the
changes are released.

Which do you think is more likely?

> For example, a variable would be
> initialized to 'None' and if it went through a loop unchanged, I

could
> determine this at the end by using a conditional type(var) ==
> type(None).


or by var == None or var is None

> What will type(None) return now?


Constants have types. What made you think that its type would change?

 
Reply With Quote
 
John J. Lee
Guest
Posts: n/a
 
      03-05-2005
Steve Holden <(E-Mail Removed)> writes:
> Warren Postma wrote:

[...]
> > gloat. Are there any really evil glitches LEFT in Python? Now go
> > look at Perl and come back and say
> > "Thank-deity-of-my-choice-I'm-using-Python".
> >

> Remaining warts that won't disappear:
>
> print >> file, stuff


Not beautiful, yes, but evil? Why?


> @decorator


Evil in the wrong hands...


John
 
Reply With Quote
 
gaudetteje@gmail.com
Guest
Posts: n/a
 
      03-05-2005
Sheesh... I didn't actually pull the type(None) comparison out of my
code. I was simply throwing together a possible situation. Had I
thought about it for more than a second I would have remembered how I
would actually use it.

Thanks for clearing up the confusion. I wasn't previously aware that
you could assign anything to None. Glad it's been changed, because
this would be the kind of thing to spawn evil code.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid - BorderStyle="None" and BorderWidth="None" doesn't work for Firefox David Freeman ASP .Net 8 02-16-2011 11:03 AM
Re: <var> is None vs. <var> == None Steve Holden Python 9 01-26-2009 09:10 PM
<var> is None vs. <var> == None Gerald Britton Python 7 01-24-2009 09:02 AM
testing for valid reference: obj vs. None!=obs vs. obj is not None alf Python 9 12-09-2006 05:00 AM
Is there a built-in method for transforming (1,None,"Hello!") to 1,None,"Hello!"? Daniel Crespo Python 5 11-13-2005 12:52 PM



Advertisments