Is there a way to define a type hint via the variable name?
Example:
Everytime I name a variable response
in my code, I want it to have a type hint to django.http.HttpResponse
.
My use case is type hinting for IDEs like PyCharm. Up to now I have no use case to evaluate this at run-time.
I would like to have general (as opposed to pycharm specific) solution.
I want to avoid doing manual and explicit type hinting over and over again.
Please tell me why you down-vote this question. I am curious and willing to learn.
Add type annotations to all methods which return a HttpResponse
A variable in Python needs to declaration. It gets created by being a lvalue (my definition, maybe there is a better way to describe this)
If
handle_request()
has a type annotation, then there is no need to do type annotation forresponse
.This does not answer the question directly, but solves the problem behind the question.
This answer is based on the comment of user Alex. Thank you :-)