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 mypy-checks to CI pipeline #29

Merged
merged 5 commits into from
Dec 10, 2024
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
27 changes: 27 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,33 @@ jobs:
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

mypy-checks:
strategy:
matrix:
pyver: ['3.8', '3.9', '3.10', '3.11', '3.12', '3.13']
fail-fast: false

runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.pyver }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mypy
pip install -r requirements-test.txt

- name: Run mypy
run: |
mypy picows # Replace with your library directory

build:
strategy:
matrix:
Expand Down
18 changes: 11 additions & 7 deletions picows/picows.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ from enum import Enum
from ssl import SSLContext
from http import HTTPStatus

# Some of the imports are deprecated in the newer python versions
# TODO: Some of the imports are deprecated in the newer python versions
# But we still have support for 3.8 where collection.abc didn't have
# proper types yet.
from typing import Final, Optional, Mapping, Iterable, Tuple, Callable, Union
# Change this to collection.abc when 3.8 support is over.
from typing import Final, Optional, Mapping, Iterable, Tuple, Callable, Union, Any
from multidict import CIMultiDict


Expand Down Expand Up @@ -161,7 +162,7 @@ class WSUpgradeResponseWithListener:
async def ws_connect(
ws_listener_factory: Callable[[], WSListener],
url: str,
*,
*args: Any,
ssl_context: Union[SSLContext, None] = None,
disconnect_on_exception: bool = True,
websocket_handshake_timeout: float = 5,
Expand All @@ -172,15 +173,18 @@ async def ws_connect(
auto_ping_strategy: WSAutoPingStrategy = ...,
enable_auto_pong: bool = True,
extra_headers: Optional[WSHeadersLike] = None,
**kwargs,
**kwargs: Any
) -> Tuple[WSTransport, WSListener]: ...

# TODO: In python 3.8 asyncio has a bug that it doesn't export Server,
# so reference it directly from asyncio.base_events.
# Soon python 3.8 support will be gone and we can annotate asyncio.Server

async def ws_create_server(
ws_listener_factory: WSServerListenerFactory,
host: Union[str, Iterable[str], None] = None,
port: Union[int, None] = None,
*,
*args: Any,
disconnect_on_exception: bool = True,
websocket_handshake_timeout: float = 5,
logger_name: str = "server",
Expand All @@ -189,5 +193,5 @@ async def ws_create_server(
auto_ping_reply_timeout: float = 20,
auto_ping_strategy: WSAutoPingStrategy = ...,
enable_auto_pong: bool = True,
**kwargs,
) -> asyncio.Server: ...
**kwargs: Any
) -> asyncio.base_events.Server: ...
Loading