Skip to content

Renaming function/class parameters should recognize calls done through functools partial #7149

@baldassarreFe

Description

@baldassarreFe

Renaming parameters of functions/classes is super useful and is - in my opinion - well implemented. The python extension automatically looks for all the places in the code where the function/class is called and applies the renaming accordingly.

However, the extension does not recognize calls that are made with functools.partial. As a consequence, when running the code, we get "TypeError: unexpected keyword argument".

Minimal example below:

Before:

from functools import partial

def foo(a: int, b: str):
    print(a, b)

def main():
    foo(a=1, b="hello")
    partial_foo = partial(foo, a=1)
    partial_foo(b="world")

if __name__ == "__main__":
    main()

Rename a to number:
Image

After:

from functools import partial

def foo(number: int, b: str):
    print(number, b)

def main():
    foo(number=1, b="hello")
    partial_foo = partial(foo, a=1)  # <- Problem here!
    partial_foo(b="world")

if __name__ == "__main__":
    main()

The renaming feature is great, but it needs to work in 100% of the cases, otherwise I'm gonna be afraid of using it.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions