Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose ServerConnection in websockets.__init__.__all__ #1560

Open
gandhis1 opened this issue Dec 2, 2024 · 1 comment
Open

Expose ServerConnection in websockets.__init__.__all__ #1560

gandhis1 opened this issue Dec 2, 2024 · 1 comment

Comments

@gandhis1
Copy link

gandhis1 commented Dec 2, 2024

In the new websockets v14, most things are re-exported on the base websockets module, which makes imports easy, I can do from websockets import serve, ConnectionClosed, broadcast for instance.

One that I cannot do is from websockets import ServerConnection. ServerProtocol is exported, can ServerConnection be exported as well? If I have a list of connections, I would want to store them in a list that is type-annotated as list[ServerConnection], and so I would need access to the type. It would be convenient to not have to reach into the separate websockets.asyncio.server module.

@aaugustin
Copy link
Member

aaugustin commented Dec 2, 2024

Importing from the root package dates back to when the library was much smaller. It has become problematic as the library has grown.

(The complexity is created by not wanting to import three implementations, including client and server, when users need just one of the six combinations. It is compounded by the need to support static typing.)

I kept backwards compatibility because forcing everyone to migrate to the new import paths would be too much busywork. However, I don't think convenience imports are a good idea, so I'm avoiding to add more.

That's how you end up with from websockets.asyncio.server import ServerConnection.

That being said, I omitted ServerConnection specifically because I expected that few users would need to import it (compared to its predecessor WebServerSocketProtocol). Indeed, the new API that became the default in 14.0 supports more use cases without subclassing. I didn't anticipate that everyone who uses typing needs to import it.

Let me think about that.

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

No branches or pull requests

2 participants