Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
jMyles opened this issue Feb 25, 2019 · 3 comments
Open

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

jMyles opened this issue Feb 25, 2019 · 3 comments

Comments

@jMyles
Copy link
Contributor

jMyles commented Feb 25, 2019

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.     
@glyph
Copy link
Member

glyph commented Feb 26, 2019

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

@jMyles
Copy link
Contributor Author

jMyles commented Feb 26, 2019

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?

@glyph
Copy link
Member

glyph commented Aug 3, 2019

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…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants