Satisfying the type checker when accessing request.sid
#2085
Answered
by
miguelgrinberg
Kalilamodow
asked this question in
Q&A
-
Type checkers give an error message (eg. def getSioSid() -> str:
sid: str = request.sid # type: ignore
return sid # type: ignore ? |
Beta Was this translation helpful? Give feedback.
Answered by
miguelgrinberg
Aug 10, 2024
Replies: 1 comment
-
Unfortunately the You can trick type checkers with a subclass of the request that declares the from typing import TYPE_CHECKING
if TYPE_CHECKING:
from flask import Request as _Request
class Request(_Request):
sid: str
request: Request |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Kalilamodow
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately the
request.sid
attribute was added long before Flask had typing annotations.You can trick type checkers with a subclass of the request that declares the
sid
attribute, done inside aTYPE_CHECKING
block. Something like this: