what kind of type hint for status code and message
Question:
Which return value type to use in
def create_or_update_gp(data: UpdateSchema) -> HERE:
try:
....logic...
return 200, {'message': 'successfully updated'}
except Exception as ex:
return 400, {'message': 'Update error'}
I can write something like Tuple[str, dict]
looks pretty general. Perhaps there is a special format for status codes? Or am I overcomplicating?
Answers:
You could use the HTTPStatus
enumeration from from http import HTTPStatus
instead of an integer and a Tuple[HTTPStatus, dict]
as the full type hint
Which return value type to use in
def create_or_update_gp(data: UpdateSchema) -> HERE:
try:
....logic...
return 200, {'message': 'successfully updated'}
except Exception as ex:
return 400, {'message': 'Update error'}
I can write something like Tuple[str, dict]
looks pretty general. Perhaps there is a special format for status codes? Or am I overcomplicating?
You could use the HTTPStatus
enumeration from from http import HTTPStatus
instead of an integer and a Tuple[HTTPStatus, dict]
as the full type hint