473,386 Members | 1,720 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Python 2.4 removes None data type?

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?

Jul 18 '05 #1
16 2058
[ga********@gmail.com]
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'>
Jul 18 '05 #2
In article <11**********************@f14g2000cwb.googlegroups .com>,
ga********@gmail.com <ga********@gmail.com> 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
Jul 18 '05 #3
ga********@gmail.com 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
Jul 18 '05 #4
Warren Postma wrote:
ga********@gmail.com 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/
Jul 18 '05 #5
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
Jul 18 '05 #6
In article <11**********************@f14g2000cwb.googlegroups .com>,
"ga********@gmail.com" <ga********@gmail.com> 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'>
Jul 18 '05 #7

ga********@gmail.com 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?

Jul 18 '05 #8
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.

Jul 18 '05 #9
Steve Holden <st***@holdenweb.com> 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
Jul 18 '05 #10
Michael Hoffman wrote:
The fact that True and False are not constants?


Yowza.

a = True
b = False
False = a
True = b
if (1==2)==True:
print "Doom"
Jul 18 '05 #11
Michael Hoffman wrote:
The fact that True and False are not constants?


Yowza.

a = True
b = False
False = a
True = b
if (1==2)==True:
print "Doom"
Jul 18 '05 #12
Warren Postma wrote:
Michael Hoffman wrote:
The fact that True and False are not constants?


Yowza.

a = True
b = False
False = a
True = b
if (1==2)==True:
print "Doom"


Why stop there when you can really cause some doom:

py> import __builtin__ as bltin
py> bltin.True, bltin.False = bltin.False, bltin.True

As an example of what doom this causes, try typing it at the interactive
prompt, and then see if you can enter anything else. I can't -- the
prompt just locks up. Woo-hoo! Another way to shoot myself (and my
users) in the foot! =)

STeVe
Jul 18 '05 #13
Steven Bethard said unto the world upon 2005-03-07 11:55:
Warren Postma wrote:
Michael Hoffman wrote:
The fact that True and False are not constants?

Yowza.

a = True
b = False
False = a
True = b
if (1==2)==True:
print "Doom"

Why stop there when you can really cause some doom:

py> import __builtin__ as bltin
py> bltin.True, bltin.False = bltin.False, bltin.True

As an example of what doom this causes, try typing it at the interactive
prompt, and then see if you can enter anything else. I can't -- the
prompt just locks up. Woo-hoo! Another way to shoot myself (and my
users) in the foot! =)

STeVe


Hi all,

just tried this in IDLE:

IDLE 1.1
import __builtin__ as bltin
bltin.True, bltin.False = bltin.False, bltin.True ================================ RESTART

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

The restart was done by IDLE itself -- poor thing just gave up. So, it
looks like Steve has found a `commit suicide' command for an IDLE
shell :-)

Best to all,

Brian vdB

Jul 18 '05 #14

ga********@gmail.com wrote:
Sheesh... I didn't actually pull the type(None) comparison out of my
code.
Sheesh yourself. Newsgroup readers can't do inspect.hasaclue('J. Random
Poster'); they rely on duck-typing or goose-typing.
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.


Indeed.

Jul 18 '05 #15
Warren Postma <wp@tekran__NOSP7M.com> writes:
ga********@gmail.com 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?


Python 2.4 (#1, Dec 1 2004, 14:23:15)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
True, False = False, True
True False


Jul 18 '05 #16
Jacek Generowicz napisał(a):
Implication: A long standing wart in Python now gone. Its time to
gloat. Are there any really evil glitches LEFT in Python?


Python 2.4 (#1, Dec 1 2004, 14:23:15)
[GCC 3.2.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
True, False = False, True
True


False


Ugh, today I've found this in some legacy code (yes, there *is* legacy
code in Python). And I will not touch this module until such syntax
become illegal.

--
Jarek Zgoda
http://jpa.berlios.de/ | http://www.zgodowie.org/
Jul 18 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
0
by: Chris McKeever | last post by:
I am trying to modify the Mailman Python code to stop mapping MIME-types and use the extension of the attachment instead. I am pretty much clueless as to what I need to do here, but I think I have...
7
by: svilen | last post by:
hello again. i'm now into using python instead of another language(s) for describing structures of data, including names, structure, type-checks, conversions, value-validations, metadata etc....
0
by: Kamilche | last post by:
""" Emulating Python inheritance manually. By loading it from disk at run time, you can create new custom types without programmer intervention, and reload them on demand, without breaking...
8
by: Paul Cochrane | last post by:
Hi all, I've got an application that I'm writing that autogenerates python code which I then execute with exec(). I know that this is not the best way to run things, and I'm not 100% sure as to...
122
by: Edward Diener No Spam | last post by:
The definition of a component model I use below is a class which allows properties, methods, and events in a structured way which can be recognized, usually through some form of introspection...
27
by: bcwhite | last post by:
I've been trying to find out what the future of Python is with regard to Tk. It seems there are several interfaces that make use of new functionality, including "Tile" and "Ttk". If I want to...
206
by: WaterWalk | last post by:
I've just read an article "Building Robust System" by Gerald Jay Sussman. The article is here: http://swiss.csail.mit.edu/classes/symbolic/spring07/readings/robust-systems.pdf In it there is a...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.