Skip to content

Create a new decorator #216

Closed Locked Answered by DayDun
survuvi asked this question in Q&A
May 20, 2023 · 2 comments · 1 reply
Discussion options

You must be logged in to vote

The error message is solved by giving the function correct types:

fn my_hello_decorator(func: fn() -> None) -> fn() capturing -> None:
    fn wrapper():
        print("Hello,")
        func()
        print("Bye Bye!")
    return wrapper

@my_hello_decorator
fn print_name():
    print("my name is Mark")

print_name()

mojo does not yet support custom decorators though, so it will just print

my name is Mark

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@survuvi
Comment options

Answer selected by survuvi
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants