Defining a type in the parameters function

It is possible to define a type in paramers in functions?

Something like this:

def __init__(self, execution_ok: int, message=None: str, additional_info=None):

It throws an error in the first : that expected a RPAREN, I suposse it expects to close the definition.

Any idea if this is possible in this version of Jython?

Thanks in advance!

You may try:

def __init__(self, execution_ok, message=None, additional_info=None):
    if not isinstance(execution_ok, int):
        raise TypeError("execution_ok must be an integer")
    if message is not None and not isinstance(message, str):
        raise TypeError("message must be a string")
    # Function logic here

Jython follows Python 2.x syntax and does not support Python 3.x features such as type hints

4 Likes