Search code examples
pythonpython-3.xfunctioncomments

How to add context comments to functions in Pythons


I've tried searching this online, however as I don't know the actual term for them I struggled to find anything of use. If i am to create my own library with a set of functions, how do i make it so that when i am using these functions in a separate script, something similar to the below yellow box appears that provides extra context and information. enter image description here

I know that by default this yellow box will show the required parameters for the specific function, however in the past i have seen these boxes contain extra added information and comments about the parameters that couldnt possibly just be added automatically by the IDE, so how do i go about adding this information to my functions, and what is the proper name for these comments? Any help is much appreciated.


Solution

  • Normally you can do things like this by just defining your params in your function, you can improve this with type hinting. You can also use a DOCstring at the start of your function to give info. however some of this may be dependent on the IDE you use. Example code

    def my_func(param1: str, param2: int, some_flag=True) -> None:
        """This is a simple function to utilise IDE tooltips and hints"""
        return None
    
    
    my_func("test", 1)
    
    

    enter image description here

    enter image description here