GithubHelp home page GithubHelp logo

Comments (3)

swistakm avatar swistakm commented on July 22, 2024

I have added this to 0.0.1 milestone to ensure that we make a decision about this feature before we will ship first official release.

from pyimgui.

swistakm avatar swistakm commented on July 22, 2024

I have realised that using keyword-only arguments here is not a good solution:

  • it will force users to use excessively verbose function calls
  • it would have to either affect all arguments with default values or be very inconsistent

The best if we could keep the core Python API as close to C++ API as possible. This is already the first reason why I have proposed this InOutABC interface. Forcing users to use keyword-only arguments will make a lot harder to port C++ examples to Python.

Fortunately I have found a simple way to handle both inout args and kwargs in a form of suggested decorator. Here is the modified code:

def allow_inout(arg_pos, kwarg_name, result_pos=1):
    def wrapper(func):
        @wraps(func)
        def wrapped(*args, **kwargs):
            try:
                kwarg = args[arg_pos]
                args = args[:arg_pos] + args[arg_pos+1:]

            except IndexError:
                kwarg = kwargs.get(kwarg_name, None)

            inout_mode = isinstance(kwarg, InOutABC)

            if inout_mode:
                kwargs[kwarg_name]=kwarg.get()

            result_tuple = func(*args, **kwargs)

            if inout_mode:
                kwarg.set(result_tuple[result_pos])

            return result_tuple

        return wrapped

    return wrapper

I still need to reconsider if maybe it would be better to handle inout kwargs explicitly in every such function. Explicit inout handling will be less expensive in terms of performance but would require more code changes and maintenance. We need to decide what is more important: more expressive and shorter code or code that executes faster.

Anyway, such change does not have to be backwards incompatible so we don't have to make any decision before the first release. I move this feature to next milestone.

from pyimgui.

swistakm avatar swistakm commented on July 22, 2024

I did some experiments in feature/8-inout-arguments branch and it doesn't seem to be as straightforward as I initially thought. I'm moving this to next milestone because I want to finally release 1.0.0

from pyimgui.

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.