Skip to content
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

Add Workers and partial ListenerHolder typing #226

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
35 changes: 34 additions & 1 deletion granian/_granian.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Any, Dict, List, Optional, Tuple
from typing import Any, Dict, List, Optional, Tuple, Protocol

from ._types import WebsocketMessage
from .http import HTTP1Settings, HTTP2Settings

__version__: str

Expand Down Expand Up @@ -58,3 +59,35 @@ class WSGIScope:

class WorkerSignal:
def __init__(self): ...

class __WorkerConfig(Protocol):
def __init__(
self,
id: int,
socket_fd: int,
threads: int,
pthreads: int,
http_mode: str,
http1_opts: HTTP1Settings,
http2_opts: HTTP2Settings,
websockets_enabled: bool,
opt_enabled: bool,
ssl_enabled: bool,
ssl_cert: Optional[str],
ssl_key: Optional[str],
):
...

class ASGIWorker(__WorkerConfig):
...

class RSGIWorker(__WorkerConfig):
...

class WSGIWorker(__WorkerConfig):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WSGIWorker doesn't accept websockets_enabled and opt_enabled parameters

...


class ListenerHolder:
@classmethod
def from_address(cls, bind_addr: str, port: int, backlog: int) -> "ListenerHolder": ...
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add from __future__ import annotations and remove the string annotation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is future annotations in re of Protocol?

also unless i'm mistaken, the class method doesn't return the instance?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, ListenerHolder.from_address returns an instance, see

pub fn from_address(_cls: &PyType, address: &str, port: u16, backlog: i32) -> PyResult<Self> {

I commented about __future__ so you can rewrite the upper as:

class ListenerHolder:
    @classmethod
    def from_address(cls, bind_addr: str, port: int, backlog: int) -> ListenerHolder: ...