tubes icon indicating copy to clipboard operation
tubes copied to clipboard

Can a function be decorated "tube"? Or only a class?

Open jMyles opened this issue 6 years ago • 3 comments

From the docstring on tube:

    """
    L{tube} is a class decorator which declares a given class to be an
    implementer of L{ITube} and fills out any methods or attributes which are
    not present on the decorated type with null-implementation methods (those
    which return None) and None attributes.

    @param cls: A class with some or all of the attributes or methods described
        by L{ITube}.

However, the readme shows:

@tube
def numbersToLines(value):
    yield str(value).encode("ascii")

Indeed, when I try to decorate a function, I get:

zope.interface.exceptions.BrokenMethodImplementation: The implementation of started violates its because implementation requires too many arguments.     

jMyles avatar Feb 25 '19 23:02 jMyles

That decorator should be @receiver, which is used in various places. @tube is only for classes now. The docs need to be updated.

glyph avatar Feb 26 '19 07:02 glyph

OK, got it. However, it actually looks like the docs source has already been so updated:

.. literalinclude:: listings/rpn.py
   :prepend: @tube
   :pyobject: linesToNumbersOrOperators

...and in rpn.py, we have:

@receiver(inputType=IFrame)
def linesToNumbersOrOperators(line):
    from operator import add, mul
    try:
        yield int(line)
    except ValueError:
        if line == b'+':
            yield add
        elif line == b'*':
            yield mul

Maybe the docs just need to be pushed to RTFD again?

jMyles avatar Feb 26 '19 18:02 jMyles

As I recall we reached some kind of resolution on this at PyCon but I don't see it reflected in this or the linked issue…

glyph avatar Aug 03 '19 21:08 glyph