Porting 3.0 to 2.6 - from __future__ import super missing?

A

andrew cooke

Hi,

I have some 3.0 code, which I would like to make work with 2.6.
However, there does not seem to be support for the new super() (no
args) via __future__. Is that correct? If so, what's the best way to
handle this?

Thanks,
Andrew
 
B

Benjamin Peterson

andrew cooke said:
Hi,

I have some 3.0 code, which I would like to make work with 2.6.
However, there does not seem to be support for the new super() (no
args) via __future__. Is that correct? If so, what's the best way to
handle this?

Just use the two argument super(): super(MyClass, instance) It's supported in
both versions.
 
A

andrew cooke

andrew cooke <andrew <at> acooke.org> writes:





Just use the two argument super(): super(MyClass, instance) It's supported in
both versions.

Thanks. Any idea how to deal with ABCs? It's sufficient to use a
simple class, but I want to expose an ABC in 3.0 as it will make it
easier for others to extend.

Unfortunately, "metaclass=" is a syntax error in 2.6 so the following
still fails:

from sys import version

if version.startswith('2.'):
class Matcher():
pass
else:
class Matcher(metaclass=ABCMeta):
pass

Andrew
 
B

Benjamin Peterson

andrew cooke said:
Unfortunately, "metaclass=" is a syntax error in 2.6 so the following
still fails:

from sys import version

if version.startswith('2.'):
class Matcher():
pass
else:
class Matcher(metaclass=ABCMeta):
pass

I would suggest that you use the 2.6 syntax, and run "2to3 -f metaclass" on your
code. (ABCs have been backported to 2.6.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top