Skip to content
Advertisement

Show names of positional arguments inlayed

I’ve recently been doing some programming in Rust using Clion. This provides a utility whereby when you pass positional arguments to a function it will show you which argument will pick up each value (as if you had passed them in as keyword arguments) see below:

edit with parameter names inlayed

I’ve found this to be a very nice feature as it’s made code a fair bit more readable and prevented me making a couple of stupid mistakes. Therefore, I’d love to have this functionality in PyCharm for programming Python, does anyone know of a plugin which can do this?

Advertisement

Answer

I think the Python Inlay Params plugin does what you want. It adds inlay hints both for callable parameters, values, and for types on variables.

Here’s a convenient snippet transcribed from the demo for testing:

class Dimens:
    width: int
    height: int

    def __init__(self, width, height):
        self.width = width
        self.height = height


a = Dimens(1, 2)

And a screenshot in action using PyCharm 2022.1 Pro

Inlay Params plugin in action

See the Settings instructions on the Python Inlay Params GitHub’s page. The above snippet worked for me using the default settings after installing the plugin.



For pytest users there’s also the Pytest Parametrize Inlay Hint. Just for type hints and not variables (thus not for parameters or values) there’s also Python Inlay Hints.

There aren’t currently any other plugins for PyCharm on JetBrains marketplace that do what you want.



It should be mentioned that using PyCharm without plugins you can already get values for parameters shown in the editor just using the debugger. For example with the following snippet:

def my_func(a: int, b: str):
    c = a
    c = c + 1
    print(str(a), b)
    return


my_func(1, 'b')

During debugging the values will be shown alongside the variables and the parameters, although not embedded in the code of the signatures themselves. As shown in the screenshot:

editor during debugging

To configure the shown functionality go to File > Settings > Build, Execution, Deployment > Debugger > Data Views and under Editor check Show values inline. See the PyCharm documentation View values inline.

IDE settings Show values inline

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement