diff --git a/http2py/api_pkg_maker.py b/http2py/api_pkg_maker.py index 55293a2..eaa43bd 100644 --- a/http2py/api_pkg_maker.py +++ b/http2py/api_pkg_maker.py @@ -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())}" @@ -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 diff --git a/http2py/cli_maker.py b/http2py/cli_maker.py index 2ff78e6..339fd45 100644 --- a/http2py/cli_maker.py +++ b/http2py/cli_maker.py @@ -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 diff --git a/http2py/client.py b/http2py/client.py index f139768..260b6d2 100644 --- a/http2py/client.py +++ b/http2py/client.py @@ -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 @@ -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": @@ -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( @@ -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 @@ -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): @@ -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) @@ -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( diff --git a/http2py/decorators.py b/http2py/decorators.py index fa93062..aa4cb99 100644 --- a/http2py/decorators.py +++ b/http2py/decorators.py @@ -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, @@ -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) diff --git a/http2py/example_cli.py b/http2py/example_cli.py index fb36c7c..55eb431 100644 --- a/http2py/example_cli.py +++ b/http2py/example_cli.py @@ -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)}") diff --git a/http2py/http2py_cls.py b/http2py/http2py_cls.py index 90916ef..4a0f680 100644 --- a/http2py/http2py_cls.py +++ b/http2py/http2py_cls.py @@ -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): @@ -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): diff --git a/http2py/py2request.py b/http2py/py2request.py index e2e7923..93ce6a6 100644 --- a/http2py/py2request.py +++ b/http2py/py2request.py @@ -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. @@ -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( @@ -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. diff --git a/http2py/testing_utils.py b/http2py/testing_utils.py index edcc61d..5de3aa4 100644 --- a/http2py/testing_utils.py +++ b/http2py/testing_utils.py @@ -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 @@ -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") diff --git a/http2py/util.py b/http2py/util.py index 752901d..f95418d 100644 --- a/http2py/util.py +++ b/http2py/util.py @@ -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