سؤال

I'm using eric4 and its rope plug-in to refactor some code. I have many method whose signatures use the *args and **kwargs syntax. I'd like to change these signatures an remove this parameters.

I've tried using the Refactoring>Refactoring>Change Method Signature but this does not remove *args and **kwargs parameters.

I wonder if this is a limitation of rope itself, or if it's eric's plug-in that does not support this feature.

هل كانت مفيدة؟

المحلول

Why do you want to remove *args and **kwargs? To refactor those functions, a refactoring library would need to perform quite a bit of introspection to know the correct parameters.

For example, how would you refactor the following function:

def f(*args, **kwargs):
    a = args[0]
    b = args[1]
    c = kwargs.get('c', 3)
    d = kwargs.get('d', 4)
    print a, b, c, d

You could turn it into:

def f(a, b, c=3, d=4):
    print a, b, c, d

It requires quite a bit of code analysis to do this already and for real functions it is even harder. The number of positional and keyword arguments can vary (e.g., the function could iterate over args) which makes it difficult to determine the correct function arguments.

Unless there is a real need, I would keep the *args and **kwargs and focus on other refactoring efforts.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top