-
-
Notifications
You must be signed in to change notification settings - Fork 352
Handling _SocketType and SocketType #2720
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
Comments
I think before deciding how to deal with that, it'd be good to try and categorise the methods - which should an implementation always need to have defined, are there groups which should be defined together? Also how many could have a default implementation, beyond A 5th option might be to use a bunch of protocols, though there'd be a little bit of a runtime cost. Make |
I think 1. is nice, because that's essentially the only method that I can think of that is both palatable and has a solid deprecation path (i.e. make certain methods abstract only at type checking time + check that they're non-abstract at initialization time, otherwise warn). |
Ah, that sounds like a good solution and relatively straightforward. The best way of categorizing methods is probably just to start writing a PR to get an overview. |
Option 5: Vaporise |
Huh, what kind of interface changes are we looking at for that sort of removal? I'm not too familiar with what trio offers w/r/t sockets. |
Why would io_uring force us to stop exposing send/recv/etc? There are ring
ops for all those, even if we do want to avoid the readiness APIs for some
reason.
…On Sun, Aug 6, 2023, 17:22 EXPLOSION ***@***.***> wrote:
Huh, what kind of interface changes are we looking at for that sort of
removal? I'm not too familiar with what trio offers w/r/t sockets.
—
Reply to this email directly, view it on GitHub
<#2720 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEU42ARXX523PB5LCJR373XUAYMBANCNFSM6AAAAAA24NREGA>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
BSD sockets is more than just
If we wanted direct sockets (a good feature), we'd then have to use the |
(We're not going to remove the current socket api, even if we do add fancy io_uring related features on top of it in the future, so for this issue it doesn't matter too much. @Fuyukai do you want to open a separate issue for possible new socket operations to expose via io_uring? E.g. you can't express a multishot accept with the current API, but we can certainly add a multishot accept API. idk what a Anyway for class SocketType:
def __init__(self, [appropriate types here]):
raise NotImplementedError
def recv(self) -> bytes:
raise NotImplementedError
# etc. That makes it legible to type checkers, while keep all the current runtime behavior the same. |
I think Default implementations could be made for all the pure wrapper methods though, if they check that the user-made class SocketType:
def __init__(self):
if type(self) == SocketType:
raise TypeError("abstract class, use trio.socket.socket...")
self._socket: _stdlib_socket.socket | None = None
def detach(self) -> int:
if self._sock is None:
raise NotImplementedError("No default implementation unless self._socket is initialized")
return self._socket.detach() |
For that case, what we do is make a protocol that has |
@TeamSpen210 just slapping on a If going in this direction I think it's probably better to just go all the way and fully merge the types, or expose |
FTR: The |
Ah, I suppose there's always class SocketType:
if TYPE_CHECKING:
def recv(self, ...) -> bytes:
...
def fileno(self) -> int:
... if we want to guarantee no impact on runtime. |
I'm having trouble following what people are trying to accomplish here –
what's wrong with my proposal above?
…On Mon, Aug 28, 2023, 07:37 John Litborn ***@***.***> wrote:
Ah, I suppose there's always
class Socket
if TYPE_CHECKING:
def recv(self, ...) -> bytes:
...
def fileno(self) -> int:
...
if we want to guarantee no impact on runtime.
—
Reply to this email directly, view it on GitHub
<#2720 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAEU42BIMWFI5IGLYTLWYKTXXSULRANCNFSM6AAAAAA24NREGA>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Your proposal can affect runtime behaviour, though admittedly only in weird cases. But I mostly just see no upside of Going into protocols and/or default implementations seemed like a good idea, but is turning out to be really messy and I'm not going to bother trying that. |
Conceptually Anyway that's the background. Agreed that the difference between I think I do have a weak preference for |
SocketType
is currently an empty type and what's meant for end-users to inherit from to show compatibility with trio sockets, but_SocketType
(which inherits fromSocketType
is what's actually used internally and has all the methods needed to get code to actually pass type checking.So we probably want to merge these one way or another, I started trying to tackle it in #2705 but all my ideas hit problems and will likely have some effect on user code that inherits from either of them, so I think it deserves it's own issue + PR.
In tests we have three different
FakeSocket
classes inheriting fromSocketType
: test_highlevel_socket.py, test_highlevel_open_tcp_stream.py and test_highlevel_open_tcp_listeners.pyOptions include:
SocketType
an abstract base class with abstract methods. Will break any code that has methods inheriting from it and not defined - so would need to only mark the methods that are absolutely required to be abstract, and others could instead raiseNotImplementedError
.*. Will almost certainly raise a lot of type checking errors.
SocketType
. I think it's impossible to avoid this being a breaking API change.SocketType = _SocketType
.*. will raise a ton of type checking errors, might be possible to reduce the number with some effort.
_SocketType
something likeInternalTrioSocketType
and have that be the class used in signatures that require some methods to be available.The text was updated successfully, but these errors were encountered: