GithubHelp home page GithubHelp logo

Run on any function automatically about enforce HOT 2 OPEN

russbaz avatar russbaz commented on May 21, 2024 2
Run on any function automatically

from enforce.

Comments (2)

RussBaz avatar RussBaz commented on May 21, 2024

Hmmm. Yes, I like how this sounds. I think it might be especially useful in debugging already running systems. However, I am not yet sure how to implement it correctly right now. I need to focus on few other problems first.

PS. Thanks for noting! I hope this project can help you at least one day.

from enforce.

jakeschurch avatar jakeschurch commented on May 21, 2024

Try this:

def CheckInputTypes(func):
    def wrapper(*args, **kwargs):

        for arg in args:
            ArgValue = next(iter(locals()['args']))
            ArgParamType = next(iter(func.__annotations__.keys()))

            if isinstance(ArgValue, func.__annotations__[ArgParamType]) is False:
                raise TypeError(
                    "Arg: {0} in function {1} is not of type {2}".format(
                        repr(ArgParamType), repr(func.__name__),
                        func.__annotations__[ArgParamType]))

        for kwarg in kwargs:
            KwargValue = locals()['kwargs'][kwarg]

            if isinstance(KwargValue, func.__annotations__[kwarg]) is False:
                raise TypeError(
                    "Kwarg: {0} in function {1} is not of type {2}".format(
                        repr(kwarg), repr(func.__name__),
                        func.__annotations__[kwarg]))

        RanFunc = func(*args, **kwargs)
        if isinstance(RanFunc, func.__annotations__['return']) is False:
            raise TypeError(
                "Return value {0} in function {1} is not of type {2}".format(
                    repr(RanFunc), repr(func.__name__),
                    func.__annotations__['return']))

        return RanFunc
    return wrapper

from enforce.

Related Issues (20)

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.