Skip to content

Satisfying the type checker when accessing request.sid #2085

Answered by miguelgrinberg
Kalilamodow asked this question in Q&A
Discussion options

You must be logged in to vote

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 a TYPE_CHECKING block. Something like this:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    from flask import Request as _Request

    class Request(_Request):
        sid: str

    request: Request

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Kalilamodow
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants