Skip to content

socket.socketpair's type parameter accepts SocketType on non-Windows #15283

Description

@gschaffner

socket.socketpair's type parameter on non-Windows platforms is annotated SocketType | int:

typeshed/stdlib/socket.pyi

Lines 1411 to 1413 in cd8b26b

defsocketpair(
family: int|AddressFamily|None=None, type: SocketType|int= ..., proto: int=0
) ->tuple[socket, socket]: ...

It seems like it should be SocketKind | int, similar to the type parameter of socket.socket and socket.fromfd:

typeshed/stdlib/socket.pyi

Lines 1319 to 1321 in cd8b26b

def__init__(
self, family: AddressFamily|int=-1, type: SocketKind|int=-1, proto: int=-1, fileno: int|None=None
) ->None: ...

deffromfd(fd: SupportsIndex, family: AddressFamily|int, type: SocketKind|int, proto: int=0) ->socket: ...

Passing a SocketKind (e.g. socket.socketpair(type=SocketKind.SOCK_STREAM)) already works fine since SocketKind is an int subtype. I don't think that SocketType is supported though. There don't appear to be any paths in CPython where a SocketType is accepted; the only two paths are

Metadata

Metadata

Assignees

No one assigned

    Labels

    stubs: false negativeType checkers do not report an error, but should

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions