Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Challenge: Type Validation Decorator | Decorators
Mastering Python: Closures and Decorators
course content

Conteúdo do Curso

Mastering Python: Closures and Decorators

Mastering Python: Closures and Decorators

1. Scopes
2. Closure
3. Decorators

bookChallenge: Type Validation Decorator

Tarefa
test

Swipe to show code editor

Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.

  1. Define the int_validate decorator that takes a func (function) as an argument.
  2. Inside int_validate(), define a wrapper function that takes a varying number of arguments.
  3. For each argument, check if its type is int. If the type is not int, raise a TypeError with the message "The function expects the integer type".
  4. Call the func() with the arguments taken by wrapper(), and return its result (don't forget to unpack the arguments).
  5. The int_validate() decorator should return the wrapper function without calling it.
  6. Decorate the int_sum() function using the int_validate decorator.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
toggle bottom row

bookChallenge: Type Validation Decorator

Tarefa
test

Swipe to show code editor

Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.

  1. Define the int_validate decorator that takes a func (function) as an argument.
  2. Inside int_validate(), define a wrapper function that takes a varying number of arguments.
  3. For each argument, check if its type is int. If the type is not int, raise a TypeError with the message "The function expects the integer type".
  4. Call the func() with the arguments taken by wrapper(), and return its result (don't forget to unpack the arguments).
  5. The int_validate() decorator should return the wrapper function without calling it.
  6. Decorate the int_sum() function using the int_validate decorator.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 3. Capítulo 4
toggle bottom row

bookChallenge: Type Validation Decorator

Tarefa
test

Swipe to show code editor

Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.

  1. Define the int_validate decorator that takes a func (function) as an argument.
  2. Inside int_validate(), define a wrapper function that takes a varying number of arguments.
  3. For each argument, check if its type is int. If the type is not int, raise a TypeError with the message "The function expects the integer type".
  4. Call the func() with the arguments taken by wrapper(), and return its result (don't forget to unpack the arguments).
  5. The int_validate() decorator should return the wrapper function without calling it.
  6. Decorate the int_sum() function using the int_validate decorator.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Tarefa
test

Swipe to show code editor

Create a decorator that validates the input data for a function, and ensure that it is flexible enough to handle functions that take a varying number of arguments.

  1. Define the int_validate decorator that takes a func (function) as an argument.
  2. Inside int_validate(), define a wrapper function that takes a varying number of arguments.
  3. For each argument, check if its type is int. If the type is not int, raise a TypeError with the message "The function expects the integer type".
  4. Call the func() with the arguments taken by wrapper(), and return its result (don't forget to unpack the arguments).
  5. The int_validate() decorator should return the wrapper function without calling it.
  6. Decorate the int_sum() function using the int_validate decorator.

Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
Seção 3. Capítulo 4
Switch to desktopMude para o desktop para praticar no mundo realContinue de onde você está usando uma das opções abaixo
We're sorry to hear that something went wrong. What happened?
some-alt