Could this line in litestar be simplified? Are the type hints correct? #4511
-
|
I have this exact line from PrometheusMiddleware in my own middleware, request = Request[Any, Any, Any](scope, receive)
method: str = request.method if request.scope["type"] == ScopeType.HTTP else request.scope["type"]and when I enabled the mypy error code "redundant-expr", that line was flagged, because request.scope["type"] is always So if the type hints are correct, I should just be able to change this to request = Request[Any, Any, Any](scope, receive)
method: str = request.methodand it would be equivalent. So the question is, is this correct? So that line in the litestar PrometheusMiddleware could also be simplified? I would just change it, but given that litestar has that line in their code, I am worried I will break something somewhere. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
|
I believe the more correct way to express this would be if connection.scope["type"] == ScopeType.HTTP:
request = Request[Any, Any, Any](scope)
method = request.method
else:
method = scope["type"]since it doesn't make sense to create a request for a non-http connection. |
Beta Was this translation helpful? Give feedback.
I believe the more correct way to express this would be
since it doesn't make sense to create a request for a non-http connection.