5 Custom Python Decorators For Your Projects

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 31

  • @michaelthomas3235
    @michaelthomas3235 21 годину тому +6

    For the type decorator, I suggest accessing the __annotations__ property of the function and use the hints as the determinate instead of inputing the types in the decorator per function. This makes the decorator more reusable and less coupled.

  • @nathanedison8692
    @nathanedison8692 23 години тому +4

    Not just useful, really helps make sense of what decorators are and how they work. Thanks!

  • @KeithFlint350
    @KeithFlint350 День тому +19

    from neuralnine import decorators

  • @barmalini
    @barmalini День тому +3

    thisl is wild, I never thought decorators were so easy

  • @thomasgoodwin2648
    @thomasgoodwin2648 8 годин тому +1

    Sorry it took so long to get back on this one. Been busy putting some of this to use. Thank you for once again taking the nightmare jungle of 'I don't have a clue' to 'Wow. that is So easy!'.
    I rewrote the type checker slightly so that it checks the arguments against the list of acceptable types (also checking for subclasses as well) so that the accepted_args acts more like a white list of ok arg types, rather than a strict 1 to 1 correlation.
    I've been paying more attention to type checking (and documentation, and error messaging) as my projects get bigger. It's time well spent not pulling out what little remains of my hair at some later point.
    Another thanks for including the informative error messages. It's so simple, and yet so effective at future stress reduction.
    Even after the years I've been here, you are STILL a freight-train of knowledge in it's simplest forms.
    🖖😎👍

  • @youngzproduction7498
    @youngzproduction7498 17 годин тому +1

    This is gold! 🎉 Thanks for your great effort.

  • @abeyroy007
    @abeyroy007 День тому +5

    Broo you are too OP 🔥
    Keep churning out more Python content...
    *PYTHON FOREVAAAAAA !!!*

  • @davewest6788
    @davewest6788 23 години тому +1

    Thanks for explaining decorators.

  • @MartinBlaha
    @MartinBlaha 23 години тому +1

    Very useful and well explained. Thank you 👋

  • @optiprime5336
    @optiprime5336 Годину тому

    Thanks for the nice presentation of the idiomatic use of python decorators. Hint to all: If you want your original function name to appear in stacktraces instead of the name of the wrapper, just add a line with @wraps(func) before the definition of the wrapper function. For this you also need an import statement like: from functools import wraps

  • @lowkeygaming4716
    @lowkeygaming4716 День тому +3

    Thanks again for another quality content

  • @halilibrahimkisakesen546
    @halilibrahimkisakesen546 23 години тому +1

    Great,thanks neurol nine. I've already find a solution to some minor bugs

  • @sigmata0
    @sigmata0 22 години тому +1

    Awesome, thank you.

  • @Mistery28543
    @Mistery28543 День тому +3

    Really useful

  • @xealit
    @xealit 2 години тому

    it's probably better to capture exceptions at the function call, not at the definition. It's a runtime thing, so should stay with the runtime. But it makes sense for scripting and API calls. I.e. it is indeed a part of the interface then: a network interface that needs retries.

  • @matias7932
    @matias7932 2 години тому

    Very usefull video. Thank you!

  • @iSJ9y217
    @iSJ9y217 7 годин тому

    Thank you for something really useful!

  • @jftuga
    @jftuga 17 годин тому

    Can you explain when you need to use "def decorator(func)" & "return decorator" and when you do not?

    • @peterholzer4481
      @peterholzer4481 10 годин тому +1

      It depends on whether you want to supply arguments or not. The language reference states "the result [of the decorator expression] must be a callable, which is invoked with the function object".
      So when you write
      @foo
      (note: no parentheses) then foo is just the name of the decorator function which needs to return the wrapper when called.
      But when you write
      @foo(bar=5, baz="hello")
      then foo(bar=5, baz="hello") will be called and must return something which in turn returns the wrapper when called. So in this case you need two nested functions.
      (This also explains why @foo() is not the same as @foo. Just in case you ever fell into that trap)

  • @jjolla6391
    @jjolla6391 2 години тому

    what plugin to vim are you using?

  • @somebody___06-j3g
    @somebody___06-j3g День тому +1

    How to Create a simple tool with UI that leverages
    AI to analyze logs of a Windows 10/11 computer to identify warnings, log off, and login time of users, the tool should automatically email a summary to
    a particular email ID.

  • @ulfrottger9171
    @ulfrottger9171 7 годин тому

    Thanks a lot!

  • @rahulkmail
    @rahulkmail День тому

    What will happen if I change value when I use, "@cache" decorator like print(process_input(6)) in any step of calling the method process_input() ?

    • @barmalini
      @barmalini День тому

      it's for you to decide, because you will have to implement that derorator and there you specify what is going to happen

  • @murphygreen8484
    @murphygreen8484 18 годин тому

    Is there an easy way to globally turn decorators on and off?

    • @enty-3035
      @enty-3035 12 годин тому

      Add an if statement to every decorators code to a veriable.

  • @Da_phuc
    @Da_phuc День тому

    Nah this is wild.

  • @ruvasqm
    @ruvasqm 7 годин тому

    awesom!

  • @skewty
    @skewty День тому

    Is old school synchronous code still being widely used outside of the learning sector and data science / AI? I have been seeing / writing async for over 5 years and seldom see benefit in pseudo threaded code.. Maybe when python and the GIL are removed things will change.. This video seems to be your learning journey in python from newb to intermediate.