nerdexam
Python_Institute

PCPP-32-101 · Question #5

Analyze the following function and choose the statement that best describes it.

The correct answer is D. The function is erroneous. If you run this code to decorator a new function, you will get name error, regardless the colon in line 3 is missing or not. NameError: name 'level2_warpper' is not defined. This is because our_function (line 4) and my_function(line 2) did not return the SAME function line 2…

Advanced OOP

Question

Analyze the following function and choose the statement that best describes it.

Exhibit

PCPP-32-101 question #5 exhibit

Options

  • AIt is an example of a decorator that accepts its own arguments.
  • BIt is an example of decorator stacking.
  • CIt is an example of a decorator that can trigger an infinite recursion
  • DThe function is erroneous.

How the community answered

(41 responses)
  • A
    10% (4)
  • B
    20% (8)
  • C
    5% (2)
  • D
    66% (27)

Explanation

If you run this code to decorator a new function, you will get name error, regardless the colon in line 3 is missing or not. NameError: name 'level2_warpper' is not defined. This is because our_function (line 4) and my_function(line 2) did not return the SAME function line 2: def level1_wrapper(my_function) line 4: return our_function To make this code correct, you can make FUNCTION_NAME in line 2 and line 4 consistency. eg. line 4 should be 'return my_function'.

Topics

#decorators#decorator arguments#decorator stacking#infinite recursion

Community Discussion

No community discussion yet for this question.

Full PCPP-32-101 Practice