Support Python 3, drop support for Python < 2.6

Bug #1096513 reported by Barry Warsaw
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.delegates
Fix Released
High
Barry Warsaw

Bug Description

This needs to be ported to Python 3 as a dependency for LP: #1096512

Related branches

Revision history for this message
Barry Warsaw (barry) wrote : Re: [Bug 1096513] Re: Support Python 3, drop support for Python < 2.6

On Jan 06, 2013, at 04:10 AM, William Grant wrote:

>If we're dropping <2.6 support we could switch it to use class
>decorators instead.

We'll have to anyway for zope.interface implements() calls, since Python 3
only supports @implementor class decorators.

Changed in lazr.delegates:
status: New → In Progress
importance: Undecided → High
assignee: nobody → Barry Warsaw (barry)
Revision history for this message
Barry Warsaw (barry) wrote :

Well, hmm... this seems to be a big problem:

File "/home/barry/projects/lazr/lp1096513/src/lazr/delegates/README.rst", line 63, in README.rst
Failed example:
    class SomeClass(object):
        delegates(IFoo)
        def __init__(self, context):
            self.context = context
Exception raised:
    Traceback (most recent call last):
      File "/usr/lib/python3.3/doctest.py", line 1287, in __run
        compileflags, 1), test.globs)
      File "<doctest README.rst[6]>", line 1, in <module>
        class SomeClass(object):
      File "<doctest README.rst[6]>", line 2, in SomeClass
        delegates(IFoo)
      File "/home/barry/projects/lazr/lp1096513/src/lazr/delegates/_delegates.py", line 91, in delegates
        addClassAdvisor(_delegates_advice, depth=2)
      File "/home/barry/projects/lazr/lp1096513/zope.interface-4.0.3-py3.3-linux-x86_64.egg/zope/interface/advice.py", line 100, in addClassAdvisor
        raise TypeError('Class advice impossible in Python3')
    TypeError: Class advice impossible in Python3

Revision history for this message
William Grant (wgrant) wrote :

If we're dropping <2.6 support we could switch it to use class decorators instead.

Revision history for this message
Barry Warsaw (barry) wrote :

So here's what I came up with.

@delegate_to(IFoo)
class Whatever:

@delegate_to(IFoo, context='myfoo')

@delegate_to(IFoo0, IFoo1, IFoo2, context='myfoo')

I like the API, but I suppose you could quibble over `delegate_to`. It has to be different from `delegates` for backward compatibility (which still works, but of course only in Python 2), and I tried `delegation`, `delegater`, and `delegates_to`, and this one reads the best to me.

FWIW, the class decorator works in Python 2.6, 2.7, 3.2, and 3.3. I completely rewrote the usage.rst file to only describe the class decorator, but I moved all the old api tests to unittest files. 100% coverage on all Pythons.

I made many of the same other changes (getting rid of buildout, switching to nosetests, etc.) that I made to lazr.smtptest.

Revision history for this message
Barry Warsaw (barry) wrote :

On Jan 07, 2013, at 12:08 AM, Barry Warsaw wrote:

>I like the API, but I suppose you could quibble over `delegate_to`. It
>has to be different from `delegates` for backward compatibility (which
>still works, but of course only in Python 2), and I tried `delegation`,
>`delegater`, and `delegates_to`, and this one reads the best to me.

@delegating(IFoo) ... ?

Barry Warsaw (barry)
Changed in lazr.delegates:
status: In Progress → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.