TypeError: объект 'NoneType' не вызывается / декораторы - PullRequest
0 голосов
/ 05 мая 2020

Код следующий, в соответствии с курсом:

def new_decorator(func):

    def wrap_func():
        print("code here before executing func")
        func()
        print("func() has been executed")

    return wrap_func()

@new_decorator
def func_needs_decorator():
    print("this function is in need for a decorator")

func_needs_decorator()

, и результат будет следующим:

code here before executing func
this function is in need for a decorator
func() has been executed
Traceback (most recent call last):
  File "decorators.py", line 17, in <module>
    func_needs_decorator()
TypeError: 'NoneType' object is not callable

Однако, если я удалю последнюю строку из кода (строка 17, func_needs_decorator ()), сообщения об ошибке нет, и результат следующий:

code here before executing func
this function is in need for a decorator
func() has been executed

Я был бы признателен за ваши советы, почему последняя строка вызывает проблему:)

1 Ответ

0 голосов
/ 05 мая 2020

ок, разобрался;)

вместо

 return wrap_func()

должно быть

 return wrap_func

.....

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...