Skip to content

Add stubs for portpicker #10944

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

Merged
merged 6 commits into from
Oct 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions stubs/portpicker/METADATA.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
version = "1.6.*"
upstream_repository = "https://github.com/google/python_portpicker"
21 changes: 21 additions & 0 deletions stubs/portpicker/portpicker.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import socket
from typing_extensions import TypeAlias

_Port: TypeAlias = int

__all__ = ("bind", "is_port_free", "pick_unused_port", "return_port", "add_reserved_port", "get_port_from_port_server")

class NoFreePortFoundError(Exception): ...

def add_reserved_port(port: _Port) -> None: ...
def return_port(port: _Port) -> None: ...
def bind(port: _Port, socket_type: socket.SocketKind, socket_proto: int) -> _Port | None: ...
def is_port_free(port: _Port) -> bool: ...
def pick_unused_port(pid: int | None = None, portserver_address: str | None = None) -> _Port: ...
def get_port_from_port_server(portserver_address: str, pid: int | None = None) -> _Port | None: ...

# legacy aliases
Bind = bind
GetPortFromPortServer = get_port_from_port_server
IsPortFree = is_port_free
PickUnusedPort = pick_unused_port