Skip to content

Handling _SocketType and SocketType #2720

@jakkdl

Description

@jakkdl

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 from SocketType 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 from SocketType: test_highlevel_socket.py, test_highlevel_open_tcp_stream.py and test_highlevel_open_tcp_listeners.py

Options include:

  1. Make 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 raise NotImplementedError.
    *. Will almost certainly raise a lot of type checking errors.
  2. Remove _SocketType, moving it all into SocketType. I think it's impossible to avoid this being a breaking API change.
  3. Don't make any runtime changes at all, but during type checking assign SocketType = _SocketType.
    *. will raise a ton of type checking errors, might be possible to reduce the number with some effort.
  4. Rename _SocketType something like InternalTrioSocketType and have that be the class used in signatures that require some methods to be available.
  5. ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions