Python Forum
Decorators and return statements
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Decorators and return statements
#2
The effect of the decorator is exactly the same as if you had written
def Divide(a, b):
    print(a/b)

Divide = smartdivide(Divide)
So Divide is redefined as the value returned by smartdivide(Divide), that is to say the function errorcheck. Now when you call Divide(), errorcheck() is actually called and it simply returns the value returned by errorcheck(). The effect of returning nothing is only a shorthand for returning the None value. Returning None has no effect with regard to script termination. The script terminates here because there are no other statements.
Reply


Messages In This Thread
Decorators and return statements - by JonEdward - Jul-24-2020, 08:42 AM
RE: Decorators and return statements - by Gribouillis - Jul-24-2020, 09:58 AM
RE: Decorators and return statements - by JonEdward - Jul-24-2020, 05:02 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Decorators @ annotation drcl 3 454 Feb-24-2024, 06:12 AM
Last Post: Gribouillis
  Does @ at sign used for tother than decorators? ggpython000 1 577 Oct-12-2023, 09:08 AM
Last Post: buran
  Variable Scopes Decorators oclmedyb 6 2,798 Jan-15-2021, 02:13 PM
Last Post: oclmedyb
  How to print cache from Decorators with Memoization OlgaM 2 2,113 Jan-29-2020, 05:06 PM
Last Post: OlgaM
  Python decorators. dodiko1d 0 9,193 Oct-13-2019, 10:23 AM
Last Post: dodiko1d
  Decorators yksingh1097 2 2,558 Aug-14-2018, 01:44 PM
Last Post: yksingh1097
  learning decorators Prince_Bhatia 6 3,365 Aug-13-2018, 02:28 PM
Last Post: Prince_Bhatia
  Multiple "return" statements or "result" variable? WolfWayfarer 7 7,868 Jul-25-2018, 07:51 AM
Last Post: perfringo
  decorators within decorators mp3909 6 4,346 Apr-02-2018, 09:47 AM
Last Post: hf8bm
  decorators mp3909 9 5,708 Mar-25-2018, 05:28 PM
Last Post: mp3909

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020