Re: 'new' module deprecation in python2.6

2008-11-29 Thread Michael Crute
On Sat, Nov 29, 2008 at 11:52 AM, David Pratt [EMAIL PROTECTED] wrote:
 Can someone tell me why 'new' has been deprecated in python 2.6 and provide
 direction for code that uses new for the future.
 I find new is invaluable for some forms of automation. I don't see a
 replacement for python 3 either. Many thanks.

You might want to take a look at PEP 3108[1] which says:

new

* Just a rebinding of names from the 'types' module.
* Can also call type built-in to get most types easily.
* Docstring states the module is no longer useful as of revision
27241 (2002-06-15).

[1] http://www.python.org/dev/peps/pep-3108/

-mike


-- 

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread David Pratt
Hi Mike. Many thanks for your reply and thank you for reference.  I  
have code that looks like the following so initially looking at what  
will need to be done as it doesn't appear new will survive. So first  
need to find way of translating this sort of thing using types. I see  
there is a ClassType for types in Python 2.6 but it does not exist in  
Python 3 so wonder where this is going? Is this an oversight or maybe  
just not ready yet.


import new

class FirstBase(object):
foo = 'bar'
biz = 'baz'

class SecondBase(object):
bla = 'blu'
buz = 'brr'

attr = {
'fiz': 'An attribute', 'fuz': 'Another one'}

Test = new.classobj(
'Test', (FirstBase, SecondBase), attr)

class MyNewClass(Test):
pass

a = MyNewClass()

print a.foo, a.buz, a.fiz, type(a)





On Nov 29, 2008, at 1:04 PM, Michael Crute wrote:

On Sat, Nov 29, 2008 at 11:52 AM, David Pratt  
[EMAIL PROTECTED] wrote:
Can someone tell me why 'new' has been deprecated in python 2.6  
and provide

direction for code that uses new for the future.
I find new is invaluable for some forms of automation. I don't see a
replacement for python 3 either. Many thanks.


You might want to take a look at PEP 3108[1] which says:

new

* Just a rebinding of names from the 'types' module.
* Can also call type built-in to get most types easily.
* Docstring states the module is no longer useful as of revision
27241 (2002-06-15).

[1] http://www.python.org/dev/peps/pep-3108/

-mike


--

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson


--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread Rob Williscroft
David Pratt wrote in news:mailman.4664.1227980181.3487.python-
[EMAIL PROTECTED] in comp.lang.python:

 import new
 
 class FirstBase(object):
  foo = 'bar'
  biz = 'baz'
 
 class SecondBase(object):
  bla = 'blu'
  buz = 'brr'
 
 attr = {
  'fiz': 'An attribute', 'fuz': 'Another one'}
 
 Test = new.classobj(
  'Test', (FirstBase, SecondBase), attr)

Test = type(
 'Test', (FirstBase, SecondBase), attr)

 
 class MyNewClass(Test):
  pass
 
 a = MyNewClass()
 
 print a.foo, a.buz, a.fiz, type(a)

print( ( a.foo, a.buz, a.fiz, type(a) ) )

py 3.0:
('bar', 'brr', 'An attribute', class '__main__.MyNewClass')
py 2.4
('bar', 'brr', 'An attribute', class '__main__.MyNewClass')

Rob.
-- 
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread David Pratt
Yeah, can just use types.ClassType instead of new.classobj, but still  
wonder what happens when we get to python 3.


Regards,
David


On Nov 29, 2008, at 1:04 PM, Michael Crute wrote:

On Sat, Nov 29, 2008 at 11:52 AM, David Pratt  
[EMAIL PROTECTED] wrote:
Can someone tell me why 'new' has been deprecated in python 2.6  
and provide

direction for code that uses new for the future.
I find new is invaluable for some forms of automation. I don't see a
replacement for python 3 either. Many thanks.


You might want to take a look at PEP 3108[1] which says:

new

* Just a rebinding of names from the 'types' module.
* Can also call type built-in to get most types easily.
* Docstring states the module is no longer useful as of revision
27241 (2002-06-15).

[1] http://www.python.org/dev/peps/pep-3108/

-mike


--

Michael E. Crute
http://mike.crute.org

God put me on this earth to accomplish a certain number of things.
Right now I am so far behind that I will never die. --Bill Watterson


--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread Christian Heimes

David Pratt wrote:
Hi Mike. Many thanks for your reply and thank you for reference.  I have 
code that looks like the following so initially looking at what will 
need to be done as it doesn't appear new will survive. So first need to 
find way of translating this sort of thing using types. I see there is a 
ClassType for types in Python 2.6 but it does not exist in Python 3 so 
wonder where this is going? Is this an oversight or maybe just not ready 
yet.


ClassType is the type of old style classes. Since old style classes were 
removed the ClassType is also gone.


You can create new style classes with type:

 Name = type(Name, (object,), dict(spam=egg))
 Name
class '__main__.Name'
 Name.spam
'egg'

Christian

--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread David Pratt

Rob. Sweet!  Many thanks.

Regards,
David

On Nov 29, 2008, at 1:46 PM, Rob Williscroft wrote:


David Pratt wrote in news:mailman.4664.1227980181.3487.python-
[EMAIL PROTECTED] in comp.lang.python:


import new

class FirstBase(object):
 foo = 'bar'
 biz = 'baz'

class SecondBase(object):
 bla = 'blu'
 buz = 'brr'

attr = {
 'fiz': 'An attribute', 'fuz': 'Another one'}

Test = new.classobj(
 'Test', (FirstBase, SecondBase), attr)


Test = type(
 'Test', (FirstBase, SecondBase), attr)



class MyNewClass(Test):
 pass

a = MyNewClass()

print a.foo, a.buz, a.fiz, type(a)


print( ( a.foo, a.buz, a.fiz, type(a) ) )

py 3.0:
('bar', 'brr', 'An attribute', class '__main__.MyNewClass')
py 2.4
('bar', 'brr', 'An attribute', class '__main__.MyNewClass')

Rob.
--
http://www.victim-prime.dsl.pipex.com/
--
http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread David Pratt

Hey Christian. Many thanks for explanation. Clears that up :-)

Regards,
David

On Nov 29, 2008, at 1:52 PM, Christian Heimes wrote:


David Pratt wrote:
Hi Mike. Many thanks for your reply and thank you for reference.   
I have code that looks like the following so initially looking at  
what will need to be done as it doesn't appear new will survive.  
So first need to find way of translating this sort of thing using  
types. I see there is a ClassType for types in Python 2.6 but it  
does not exist in Python 3 so wonder where this is going? Is this  
an oversight or maybe just not ready yet.


ClassType is the type of old style classes. Since old style classes  
were removed the ClassType is also gone.


You can create new style classes with type:

 Name = type(Name, (object,), dict(spam=egg))
 Name
class '__main__.Name'
 Name.spam
'egg'

Christian

--
http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list


Re: 'new' module deprecation in python2.6

2008-11-29 Thread Scott David Daniels

David Pratt wrote:

...
import new

class FirstBase(object):
foo = 'bar'
biz = 'baz'

class SecondBase(object):
bla = 'blu'
buz = 'brr'

attr = {
'fiz': 'An attribute', 'fuz': 'Another one'}

Test = new.classobj(

^^^ replace with:
  Test = type(

'Test', (FirstBase, SecondBase), attr)

class MyNewClass(Test):
pass

a = MyNewClass()

print a.foo, a.buz, a.fiz, type(a)

 ...

It's really that simple.

--Scott David Daniels
[EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list