Re: [Python-Dev] Core projects: 3to2

2009-03-19 Thread andrew cooke
Terry Reedy wrote:
> Antoine Pitrou wrote:
>> Terry Reedy  udel.edu> writes:
>>> Some of the people who need to support both late 2.x and 3.x would
>>> prefer to write 3.x code and backport.  The OP of a current python-list
>>> thread asked whether there was any way to write something like
>>>
>>> @alias('__nonzero__')
>>> def __bool__(self): return True
>>
>> How about simply:
>> __nonzero__ = __bool__
>>
>>> I believe my own 3.0 code will mainly also need
>>> print() to print statement
>>
>> If this is only about supporting "late 2.x" (i.e., 2.6 and upwards), you
>> can
>> already write:
>
> People often do not specify.  I suspect some are thinking back to 2.5,
> but that will change in the future.


i am the author of the original post quoted above.  i wrote a parser
library (lepl) using 3.0.  backporting to 2.6 was fairly easy, but it
still does not run with 2.5.

if i remember correctly it appeared that i was going to need separate
source files because of significant differences in syntax (print,
exceptions) as well as missing functionality (metaclasses, string
formatting).

andrew


___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Core projects: 3to2

2009-03-19 Thread Terry Reedy

Antoine Pitrou wrote:

Terry Reedy  udel.edu> writes:
Some of the people who need to support both late 2.x and 3.x would 
prefer to write 3.x code and backport.  The OP of a current python-list 
thread asked whether there was any way to write something like


@alias('__nonzero__')
def __bool__(self): return True


How about simply:
__nonzero__ = __bool__


I believe my own 3.0 code will mainly also need
print() to print statement


If this is only about supporting "late 2.x" (i.e., 2.6 and upwards), you can
already write:


People often do not specify.  I suspect some are thinking back to 2.5, 
but that will change in the future.



from __future__ import print_function


I was not aware of that.  Would be ok for my current project which has 
print isolated in a few modules, at least so far.



except e as a to 2.x version


Works in 2.6.


Did not know that.  Perhaps a 3 to 2.6+ guide would help.



class C() to class C(object)


Part of the reason to move to 3.0 is to not have to do that.


__metaclass__ = type

Now I'm not saying that all 3.0 code will work in 2.6 with such simple
precautions, far from it!


tjr

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Core projects: 3to2

2009-03-18 Thread Benjamin Peterson
2009/3/18 Antoine Pitrou :
>
>> class C() to class C(object)
>
> __metaclass__ = type

Or even better: just inherit from object in 3.0 and 2.x. :)



-- 
Regards,
Benjamin
___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Core projects: 3to2

2009-03-18 Thread Antoine Pitrou
Terry Reedy  udel.edu> writes:
> 
> Some of the people who need to support both late 2.x and 3.x would 
> prefer to write 3.x code and backport.  The OP of a current python-list 
> thread asked whether there was any way to write something like
> 
>   @alias('__nonzero__')
>   def __bool__(self): return True

How about simply:
__nonzero__ = __bool__

> I believe my own 3.0 code will mainly also need
> print() to print statement

If this is only about supporting "late 2.x" (i.e., 2.6 and upwards), you can
already write:

from __future__ import print_function

> except e as a to 2.x version

Works in 2.6.

> class C() to class C(object)

__metaclass__ = type

Now I'm not saying that all 3.0 code will work in 2.6 with such simple
precautions, far from it!

Regards

Antoine.


___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com


Re: [Python-Dev] Core projects: 3to2

2009-03-18 Thread Terry Reedy

Antoine Pitrou wrote:

Terry Reedy  udel.edu> writes:

Or the much requested 3to2 using the same tools.


I didn't know there was such a request. I thought it was only a PyPy April fool.


Some of the people who need to support both late 2.x and 3.x would 
prefer to write 3.x code and backport.  The OP of a current python-list 
thread asked whether there was any way to write something like


@alias('__nonzero__')
def __bool__(self): return True

(in preference to explicit 'if version') and have .__bool__ be 
either replaced or aliased as .__nonzero__ for a 2.x version.  Answer: 
No.  Use 3to2 if/when available.


This has been the answer in other threads as well.

I believe my own 3.0 code will mainly also need
print() to print statement
except e as a to 2.x version
class C() to class C(object)

An easily doable project would be both used and appreciated.

tjr

___
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com