Git Product home page Git Product logo

pyp-w3-gw-decorators-library's Introduction

[pyp-w3] Decorators Library

Today we will work with decorators. This project aims to be a library of useful, multi purpose decorators.

We provide an initial set of decorators you must implement, with all their proper test cases, but the interesting thing about this project is that you must also use your imagination and creativity to implement new decorators out of the initial set we provide. Of course, all the new decorators must come with their own set of test cases.

Decorators provided

This is the initial set of decorators you must implement:

timeout decorator

Useful to given functions a certain max time for execution. The decorator is suppose to track the execution time and raise and exception if the time exceeds given timeout range. Example:

@timeout(1)
def very_slow_function():
    time.sleep(2)

>>> very_slow_function()
TimeoutError: Function call timed out

debug decorator

This decorator is suppose to debug the executions of the decorated function by logging a message before starting the execution including given params, and a second message after the execution is finished with the returned result. Example:

@debug()
def my_add(a, b):
    return a + b

>>> my_add(1, 2)
Executing "my_add" with params: (1, 2), {}
Finished "my_add" execution with result: 3
3

count_calls decorator

Keeps track of how many times certain function was called. Example:

@count_calls
def my_func():
   pass

>>> my_func()
>>> my_func()
>>> my_func()
>>> my_func()
>>> my_func.counter()
4

memoized decorator

This decorator should keep track of previous executions of the decorated function and the result of the invokations. If the decorated function is execution again using the same set of arguments sent in the past, the result must be immediately returned by an internal cache instead of re executing the same code again. Example:

@memoized
def add(a, b):
    return a + b

>>> add(1, 2)
3
>>> add(2, 3)
5
>>> add(1, 2)
3  # `add` was not executed, result was returned from internal cache

As we said before, a second requirement of this group work is to also implement new decorators out of this initial set. We require at least Two more decorators with their proper test cases. Adding even more than 2 will give you some extra points.

pyp-w3-gw-decorators-library's People

Contributors

martinzugnoni avatar santiagobasulto avatar pkkondamuri avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.