Skip to content
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
4 changes: 2 additions & 2 deletions http2py/api_pkg_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def api_pkg_files(
}


def _mk_pkg_name():
def _mk_pkg_name() -> str:
return f"apipkg{int(datetime.now(timezone.utc).timestamp())}"


Expand Down Expand Up @@ -328,7 +328,7 @@ def mk_api_pkg(
shutil.rmtree(tempdir)


def _check_build_backend():
def _check_build_backend() -> None:
"""Fail early and legibly when the interpreter cannot build an sdist.

``setup.py sdist`` needs setuptools in the *subprocess's* interpreter, which
Expand Down
2 changes: 1 addition & 1 deletion http2py/cli_maker.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def mk_cli(
return cw.mk_parser(cli_methods, convention=CLI_CONVENTION)


def dispatch_cli(*args, **kwargs):
def dispatch_cli(*args, **kwargs) -> None:
"""Makes a CLI parser with mk_cli and then runs it (see documentation of mk_cli)

Returns ``None`` when the command ran, and raises ``SystemExit(2)`` on a
Expand Down
14 changes: 7 additions & 7 deletions http2py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(
binary_loads=None,
binary_dumps=DFLT_BINARY_DUMPS,
**auth_kwargs,
):
) -> None:
"""
Initialize the client with an OpenAPI spec and optional authentication inputs

Expand Down Expand Up @@ -135,7 +135,7 @@ def __init__(
url_template, http_method, openapi_method_spec, pathname=pathname
)

def init_security(self, openapi_spec, **auth_kwargs):
def init_security(self, openapi_spec, **auth_kwargs) -> None:
security = openapi_spec["security"]
auth_type = list(security.keys())[0]
if auth_type == "apiKey":
Expand Down Expand Up @@ -163,7 +163,7 @@ def init_security(self, openapi_spec, **auth_kwargs):

def register_method(
self, url_template, http_method, openapi_method_spec, *, pathname=None
):
) -> None:
content_type = None
if "requestBody" in openapi_method_spec:
content_type = next(
Expand Down Expand Up @@ -235,7 +235,7 @@ def _unique_derived_name(self, name, url_template):
)
return unique

def _can_be_route_attribute(self, name):
def _can_be_route_attribute(self, name) -> bool:
"""Whether a route called ``name`` may be set as an attribute of the client:
the name is public, and is not an attribute the client works with already
(an earlier route of the same name, or a ``_route_shadowable_attrs`` one, can
Expand All @@ -252,7 +252,7 @@ def handle_request(self, method, url, **_request_kwargs):
self.ensure_login()
return self.session.request(method, url, **_request_kwargs)

def set_header(self, header):
def set_header(self, header) -> None:
self.session.headers.update(header)

def ensure_login(self):
Expand Down Expand Up @@ -284,7 +284,7 @@ def refresh_login(self):
).json()
return self.receive_login(refresh_result)

def receive_login(self, login_result):
def receive_login(self, login_result) -> None:
error = login_result.get("error", None)
if error:
raise AuthorizationError(error)
Expand All @@ -296,7 +296,7 @@ def receive_login(self, login_result):
elif key in self.refresh_input_keys:
self.refresh_inputs[key] = value

def set_profile(self, profile: str, config: str = DFLT_CONFIG_FILENAME):
def set_profile(self, profile: str, config: str = DFLT_CONFIG_FILENAME) -> None:
new_auth = mk_auth({}, self.login_input_keys, config, profile)
if not new_auth:
raise KeyError(
Expand Down
4 changes: 2 additions & 2 deletions http2py/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import warnings
from collections.abc import Callable
from functools import partial
from typing import Any, Optional
from typing import Any, Optional, NoReturn

from i2.errors import (
AuthorizationError,
Expand All @@ -40,7 +40,7 @@
from http2py.constants import BINARY_CONTENT_TYPE, JSON_CONTENT_TYPE, RAW_CONTENT_TYPE


def _handle_error(resp):
def _handle_error(resp) -> NoReturn:
if resp.status_code == 400:
if resp.reason == "AuthorizationError":
raise AuthorizationError(resp.text)
Expand Down
2 changes: 1 addition & 1 deletion http2py/example_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from i2.io_trans import AnnotAndDfltIoTrans


def myfun(a: int, b: Iterable[int]):
def myfun(a: int, b: Iterable[int]) -> None:
print(f"a: {a} {type(a)}")
print(f"b: {b} {type(b)}")

Expand Down
4 changes: 2 additions & 2 deletions http2py/http2py_cls.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@


class Http2Py:
def __init__(self, session=None):
def __init__(self, session=None) -> None:
self.session = session or Session()

def __enter__(self):
Expand All @@ -13,7 +13,7 @@ def __enter__(self):
def __exit__(self, *args):
self.close()

def set_headers(self, headers):
def set_headers(self, headers) -> None:
self.session.headers.update(headers)

def close(self):
Expand Down
6 changes: 3 additions & 3 deletions http2py/py2request.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,7 @@ def __init__(
method_specs=None,
method_func_from_method_spec=DFLT_METHOD_FUNC_FROM_METHOD_SPEC,
**kwargs,
):
) -> None:
"""
Initialize the object with web request calling methods.
You can also just make an empty Py2Request object, and inject methods later on, one by one.
Expand Down Expand Up @@ -456,7 +456,7 @@ def gen():

def _inject_method(
self, method_name, method_spec, method_func_from_method_spec=None
):
) -> None:
method_wrap = None
if not callable(method_spec):
method_spec, method_wrap = _mk_method_func_and_wrap(
Expand Down Expand Up @@ -564,7 +564,7 @@ class UrlMethodSpecsMaker:
Utility to help in making templated method_specs dicts to be used to define a Py2Request object.
"""

def __init__(self, url_root, constant_url_query=None, **constant_items):
def __init__(self, url_root, constant_url_query=None, **constant_items) -> None:
r"""
Make a method_spec factory.

Expand Down
10 changes: 6 additions & 4 deletions http2py/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@


class MockHttpClient(HttpClient):
def __init__(self, openapi_spec=None, session_state=None, url=None, **auth_kwargs):
def __init__(
self, openapi_spec=None, session_state=None, url=None, **auth_kwargs
) -> None:
self.ping.method_spec = {}

def add_mock_methods(self, methods):
def add_mock_methods(self, methods) -> None:
for method_def in methods:

def _method(*args, **kwargs):
def _method(*args, **kwargs) -> None:
pass

new_method = _method
Expand Down Expand Up @@ -45,7 +47,7 @@ def ping(self):
# TODO: fill this out. Needs type annotations on the methods
# (types should be extracted in mk_method_spec_from_openapi_method_spec and then
# used to make annotations in mk_request_function)
def mk_unit_tests(client):
def mk_unit_tests(client) -> None:
for method_name in dir(client):
method = getattr(client, method_name)
method_spec = getattr(method, "method_spec")
Expand Down
2 changes: 1 addition & 1 deletion http2py/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
)


def is_jsonable(x):
def is_jsonable(x) -> bool | None:
try:
json.dumps(x)
return True
Expand Down
Loading