python - Overriding/Patching function from third-party module -


I am looking for the best practice method to overwrite / patch a function that is being imported from a third-party module For example, in my code I am importing and using the function like this:

  some_function from somemodule import foo = 3 bar = 5 some_function (foo, bar)  

Now I would like to override some_function with my function My own function, I want to do some magic I would like to call and then call the general function.

Now, I am doing this:

  some_function from some modules import Some_function_original def some_function (f, b): # some magic return some_function_original (f, b) Foo = 3 times = 5 some_function (foo, bar)  

However, I want to avoid "[..] to [..] as [..] As [..] "and name the original function and just overwrite it / patch it?

Import the module namespaces instead of just the exact function? Import Somemodule def some_function (f, b): # some magic return somemodule .some_function (f, b) foo = 3 times = 5 some_function (foo, bar) < / Pre>


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -