I want to specify my function with correct type hints for return values. My function receives data as a dictionary and returns the modification. It also returns a status code as integer to check if the modification was successfull. For example I want to specify something like this:
def reworkData(measurement:dict)->dict,int:
...
return measurement,0
This currently results in invalid syntax. How can I do this?
From Python 3.5 to 3.8 you want Tuple[dict, int] in order to specify that you will return both as Python will return them as a tuple.
from typing import Tuple
def rework_data(measurement: dict) -> Tuple[dict, int]:
...
return measurement, 0
As of Python 3.9 Tuple is deprecated and you should use the builtin type
def rework_data(measurement: dict) -> tuple[dict, int]:
...
return measurement, 0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With