question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Hook to apply decorators

See original GitHub issue

Description

Hook to apply decorators

Context

Decorators are useful to modify behaviors of multiple node functions. Kedro 0.18.0 will deprecate applying decorators by decorate method of kedro.pipeline.Pipeline and it is encouraged to use hooks to apply decorators, but there are no official hooks to apply decorators.

Possible Implementation

Provide hooks to apply decorators

Possible Alternatives

Continue to support decorators by kedro.pipeline.Pipeline even in Kedro 0.18.0 and later.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
AntonyMilneQBcommented, Mar 17, 2021

If you prefer chaining decorators together like in the existing Node.decorate notation, then you should be able to write a small helper function to do this. Something like:

def decorate(function: Callable, *decorators: Callable) -> Callable:
    for decorator in reversed(decorators):
        function = decorator(function)
    return function

class ProjectHooks:
    @hook_impl
    def before_node_run(self, node: Node):
        node.func = decorate(node.func, deco1, deco2, deco3)

This should achieve node.func = deco1(deco2(deco3(node.func))) without needing to explicitly do the nesting.

1reaction
Minyuscommented, Mar 17, 2021

Thanks @AntonyMilneQB . Yes, using decorators as functions like node.func = log_time(node.func) seems to work fine. To use multiple decorators, however, the decorators need to be nested like node.func = deco1(deco2(deco3(node.func))), and it doesn’t look like Kedro’s style though. Anyway, thanks for a workable suggestion!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Decorators vs Hooks - Procore
With Hook. With the hook, it is easy to use multiple copies of the same piece of state, in this case, Visibility. However,...
Read more >
Decorating React hook with Typescript - DEV Community ‍ ‍
In this tutorial we'll see how a React hook can be decorated using a higher order function and even have its return type...
Read more >
Primer on Python Decorators
In this introductory tutorial, we'll look at what Python decorators are and how to create and use them.
Read more >
18 in. White Snap Install Hook Rack with 4 Satin Nickel Pill ...
The Home Decorators Collection 18 inch white SNAP hook rack with satin nickel pill top hooks is a stylish rack that conceals the...
Read more >
Before Hooks - The Falcon Web Framework - Read the Docs
Falcon supports before and after hooks. You install a hook simply by applying one of the decorators below, either to an individual responder...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found