You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
The text was updated successfully, but these errors were encountered:
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.
In the new websockets v14, most things are re-exported on the base
websockets
module, which makes imports easy, I can dofrom websockets import serve, ConnectionClosed, broadcast
for instance.One that I cannot do is
from websockets import ServerConnection
.ServerProtocol
is exported, canServerConnection
be exported as well? If I have a list of connections, I would want to store them in a list that is type-annotated aslist[ServerConnection]
, and so I would need access to the type. It would be convenient to not have to reach into the separatewebsockets.asyncio.server
module.The text was updated successfully, but these errors were encountered: