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?

Asked By: Jekson

||

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

Answered By: justin
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.