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

Adding type check for serve.py #1652

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions lightly/api/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
paths: Sequence[Path],
host: str,
port: int,
):
) -> ThreadingHTTPServer:
"""Returns an HTTP server that serves a local datasource.

Args:
Expand Down Expand Up @@ -42,7 +42,7 @@
self.send_header("Access-Control-Allow-Methods", "GET, POST, OPTIONS")
self.end_headers()

def send_response_only(self, code, message=None):
def send_response_only(self, code: int, message: str | None = None) -> None:

Check warning on line 45 in lightly/api/serve.py

View check run for this annotation

Codecov / codecov/patch

lightly/api/serve.py#L45

Added line #L45 was not covered by tests
Copy link
Contributor

@guarin guarin Sep 24, 2024

Choose a reason for hiding this comment

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

Could you change this to use Optional (can be imported with from typing import Optional)?

Suggested change
def send_response_only(self, code: int, message: str | None = None) -> None:
def send_response_only(self, code: int, message: Optional[str= None) -> None:

The package is still used on some older Python versions (<3.10) which do not yet support the new X | Y typing syntax introduced in 3.10. This is usually caught by our tests but this specific function is not tested :(

Edit: Actually, let's just add from __future__ import annotations at the top of the file. Then Python 3.10 types are also supported on older versions.

Copy link
Author

Choose a reason for hiding this comment

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

okay, will add and crate a PR

Copy link
Contributor

Choose a reason for hiding this comment

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

No need to create a new PR, you can just update this one.

super().send_response_only(code, message)
self.send_header(
"Cache-Control", "no-store, must-revalidate, no-cache, max-age=-1"
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,6 @@ exclude = '''(?x)(
lightly/api/api_workflow_download_dataset.py |
lightly/api/bitmask.py |
lightly/api/_version_checking.py |
lightly/api/serve.py |
lightly/api/patch.py |
lightly/api/swagger_api_client.py |
lightly/api/api_workflow_collaboration.py |
Expand Down
Loading