Skip to content

Conversation

@Kludex
Copy link
Owner

@Kludex Kludex commented Oct 9, 2025



class Request(HTTPConnection):
class Request(HTTPConnection[StateT]):
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are missing the same in WebSockets.

strategy:
matrix:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14"]
python-version: ["3.10", "3.11", "3.12", "3.13", "3.14"]
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just so the pipeline can pass, but we shouldn't merge this here.

@Kludex
Copy link
Owner Author

Kludex commented Oct 9, 2025

@alex-oleshkevich @abersheeran Can you check this, please?

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

@Kludex
Copy link
Owner Author

Kludex commented Oct 9, 2025

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

In the sense that this implementation makes sense, or something different? 🤔

@alex-oleshkevich
Copy link
Contributor

@alex-oleshkevich @abersheeran Can you check this, please?

All good.

In the sense that this implementation makes sense, or something different? 🤔

We want to have a typed request state and keep backward compatibility. That was achieved, so all is good :)

@patrick91
Copy link

This was exactly what I had in mind :D thanks @Kludex!



class HTTPConnection(Mapping[str, Any]):
StateT = TypeVar("StateT", bound=Mapping[str, Any] | State, default=State)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this will pass the TypedDict check in some static type checkers.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which one you don't think it will not? We test with mypy here, but pyright doesn't seem to be failing (I use it on my environment).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's great to be able to pass the inspection.

@PerumallaGiridhar
Copy link

Hi there! 👋
I’ve added tests to help increase coverage around typed request.state in #3049.
This is my first contribution to Starlette (and to open source in general)
I’d love to keep contributing in this area to help unblock and accelerate improvements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make request.state generic

6 participants