Skip to content

Commit

Permalink
Remove mentions of staticmethod and fix annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
sanjacob committed Aug 19, 2024
1 parent 77cdfe3 commit a8347e8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
5 changes: 2 additions & 3 deletions docs/quick.rst
Original file line number Diff line number Diff line change
Expand Up @@ -249,12 +249,11 @@ throw an `APIStatusError`.

`status_handler` is called with three arguments:
the client instance, the status code, and the entire
`response.json()` object. Use `@staticmethod` if needed.
`response.json()` object.

::

@staticmethod
def my_handler(error_code, response):
def my_handler(client, error_code, response):
raise ValueError(error_code)


Expand Down
3 changes: 1 addition & 2 deletions tests/test_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ def get_my_endpoint(self, response):


def test_class_decorator_parameter_status_handler_throws(mock_requests, example_url):
@staticmethod
def throw_custom(error_code, response):
def throw_custom(client, error_code, response):
raise ValueError(error_code)

@api_client(example_url, status_key='custom_error',
Expand Down
4 changes: 3 additions & 1 deletion tiny_api_client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
T = TypeVar('T')

APIStatusHandler = Callable[[Any, Any, Any], None] | None
_StatusHandler = Callable[[Any, Any], None] | None

APIClient = TypeVar('APIClient', bound=type[Any])


Expand Down Expand Up @@ -159,7 +161,7 @@ def _make_request(client: Any, method: str, endpoint: str,
def _handle_response(response: Any,
json: bool, xml: bool,
status_key: str, results_key: str,
status_handler: APIStatusHandler) -> Any:
status_handler: _StatusHandler) -> Any:
"""Parse json or XML response after request is complete"""
endpoint_response: Any = response

Expand Down

0 comments on commit a8347e8

Please sign in to comment.