Open
Description
The Pipe decorator does not work on methods defined on a class.
This would be useful to make a pipe out of an existing method. As an example, I can do something like this:
class Job(requests.Session):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
def get(self, items, url, *args, **kwargs):
for item in items:
yield super().get(url.format(item), *args, **kwargs).json()
def jq(self, items, stmt):
compiled = jq.compile(stmt)
for item in items:
yield from iter(compiled.input_value(item))
job = Job()
x = (
["hansthen", "JulienPalard"] |
Pipe(job.get)("https://api.github.com/users/{}/repos") |
Pipe(job.jq)(".[].license // empty | .name")
)
But I would rather create a the Pipe at class level like this:
class Job(requests.Session):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@Pipe
def get(self, items, url, *args, **kwargs):
for item in items:
yield self.session.get(url.format(item), *args, **kwargs).json()
@Pipe
def jq(self, items, stmt):
compiled = jq.compile(stmt)
for item in items:
yield from iter(compiled.input_value(item))
job = Job()
x = (
["hansthen", "JulienPalard"] |
job.get("https://api.github.com/users/{}/repos") |
job.jq(".[].license // empty | .name")
)
Could you add a recipe to make the Pipe class work with class methods?
Metadata
Metadata
Assignees
Labels
No labels