Search code examples
pythondocstring

Is there something like "f-docstring"?


I want to mention default values for function arguments in the function descriptions (docstrings). What I don't want to do is to manually edit the docstrings, whenever I try out new default values

So, is there something like f-docstrings, that enables dynamically updating the decstrings content ?

I tried

def check_availability(self, checks: int = 10, timeout: float = 1.5, apply_filters: bool = False) -> list[dict]:
    f'''
    Checks which proxies on "https://free-proxy-list.net/" are really available 
    by requesting visible IP returned by "http://icanhazip.com"  

    Args:
        checks (int): amount of checks, corresponds to the first entries in the considered proxies list); defaults to {checks}
        timeout (float): accepted response waiting time in seconds.
        apply_filters (bool): If True a before generated filtered proxies list is considered for the checks, otherwise the entire list is considered.

    Returns:
        list[dict]: list of confirmed proxies
    '''

When I hover over a call of that method I get this: enter image description here

This is how it shouldf look like:

enter image description here


Solution

  • whenever I try out new default values

    Two things:

    1. When experimenting, just pass the actual values to the function rather than updating the default values every time. These are function arguments for a reason.
    2. In the screenshot you provided, the default values are clearly visible outside the docstring, in the method definition. You might consider omitting default values from the docstring entirely, since they're visible in the method declaration.