0

I have an architecture, where I use wrapper for calling functions from package module. Inside the module there is a function that calls another three. I need to override one of them in run-time. Exactly I need to change parameters that are forwarded to another set of functions being called.

Here is a case sample:

a.py

import b_wrapper as wrapper

def foo():
    if wrapper.bar(parameter):
    """some more code goes here"""

b_wrapper.py

import some.package.module as module

def bar(parameter):
    return module.baz(veryImportantParameter, parameter)

file.py

def functionThree(par):  # needs to be overwritten
    """more functions called forwarding par as a parameter"""

def baz(veryImportantParameter, parameter)
    functionOne(veryImportantParameter, otherParameters)
    functionTwo(veryImportantParameter, someMoreParameters)
    functionThree(veryImportantParameter, parameterToChange, evenMoreParameters)

What I tried to do is overriding in wrapper file, didn't work out, as other functions are interfering with it. As reference used this post.

I'm not quite sure that this is doable, because of unique functions that are called inside this module, also looking for alternatives that won't require overriding portion of module.

Edit: mixing up arguments and parameters is intentional for demonstration purpose only.

ntrme
  • 59
  • 6
  • It feels to me like you're looking for some sort of intermediate _object_ that has the additional parameters you need. Trying to do it only at the module level and (presumably) with global variables doesn't seem right. "Overriding functions" isn't something I'd generally try to do in Python (except at a class/inheritance level). – David Maze Jul 11 '18 at 11:19
  • @DavidMaze it would be simpler if I had to deal with classes, then I'd have much more freedom, but at I'm forced to work with functions and trying to override function local variables by overriding function. I'm honestly stuck here and I guess that I'll have to just rewrite portion of code. – ntrme Jul 11 '18 at 11:46

0 Answers0