Skip to content

Request for review: Decorator implementation example #134500

Not planned
@ShengDong207

Description

@ShengDong207

I'm learning about Python decorators and would appreciate feedback on my implementation.

Here's my example code:

@timer
def slow_function():
    import time
    time.sleep(2)
    return "Done"

Specifically, I'd like to know:

  1. Is this a correct usage of decorators?
  2. What's missing from the implementation (I notice the @timer decorator itself isn't defined)
  3. Best practices for implementing timing decorators

Thank you for your help!

Activity

hugovk

hugovk commented on May 22, 2025

@hugovk
Member

This is the issue tracker for the Python language itself.

Please open a topic in the help forum to ask about your own code:

https://discuss.python.org/c/help/7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Request for review: Decorator implementation example · Issue #134500 · python/cpython

      Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

      Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant