How to write docstring in python to specify that a parameter can assume only a set of values

Viewed 145

Good morning everybody,

I need to know if there is a way, at the moment I say no, for having the behavior I write in JavaScript also in Python.

If in JavaScript, when I have a function with a parameter that can assume only some values, I write the following code

/**
 * Set the status of session
 * @param {('ACTIVE'|'LOCKED'|'UNAUTHORIZED')} status
 */
function set(status = 'UNAUTHORIZED') {
    console.log(status);
}

Writing in this way, calling the function makes my IDE (PHPStorm) to suggest me the list of values I can use as shown in the following image

enter image description here

This is my function in Python

def set(status: str) -> None:
    """
    Set the status of session

    :param status: ('ACTIVE','LOCKED','UNAUTHORIZED')

    :return:
    :rtype: None
    """
    print(status)

but I can't get the same result with IDE (PYCharm) probably because the syntax of docstring is wrong.

enter image description here

Is there a way to get in Python the same result I have in JavaScript? For example, if I wrote the same function, how can I define the list of values that the parameter can assume?

Thanks to all of you

0 Answers
Related