Skip to content

Commit 33f1933

Browse files
echarrodclaude
andauthored
precommit: Fix all pre-commit violations (#73)
* precommit: Fix all pre-commit violations - Add module docstrings to all Python files - Add class and method docstrings where missing - Fix docstring formatting (imperative mood, periods) - Remove unused imports - Improve test error matching with pytest.raises - Configure bandit to skip B107 for empty credential defaults - All pre-commit hooks now pass 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]> * error: Add type params --------- Co-authored-by: Claude <[email protected]>
1 parent 1aec6cd commit 33f1933

File tree

9 files changed

+214
-139
lines changed

9 files changed

+214
-139
lines changed

examples/readonly.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
"""Example script demonstrating read-only API calls to Luno."""
2+
13
import os
24
import time
35

luno_python/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
"""Luno Python SDK."""
2+
13
VERSION = "0.0.10"

luno_python/base_client.py

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
"""Base HTTP client for Luno API."""
2+
13
import json
24
import platform
35

46
import requests
5-
import six
67

78
try:
89
from json.decoder import JSONDecodeError
@@ -20,8 +21,11 @@
2021

2122

2223
class BaseClient:
24+
"""Base HTTP client for making authenticated requests to the Luno API."""
25+
2326
def __init__(self, base_url="", timeout=0, api_key_id="", api_key_secret=""):
24-
"""
27+
"""Initialise the base client.
28+
2529
:type base_url: str
2630
:type timeout: float
2731
:type api_key_id: str
@@ -34,7 +38,7 @@ def __init__(self, base_url="", timeout=0, api_key_id="", api_key_secret=""):
3438
self.session = requests.Session()
3539

3640
def set_auth(self, api_key_id, api_key_secret):
37-
"""Provides the client with an API key and secret.
41+
"""Set the API key and secret for authentication.
3842
3943
:type api_key_id: str
4044
:type api_key_secret: str
@@ -43,7 +47,7 @@ def set_auth(self, api_key_id, api_key_secret):
4347
self.api_key_secret = api_key_secret
4448

4549
def set_base_url(self, base_url):
46-
"""Overrides the default base URL. For internal use.
50+
"""Set the base URL for API requests.
4751
4852
:type base_url: str
4953
"""
@@ -52,7 +56,7 @@ def set_base_url(self, base_url):
5256
self.base_url = base_url.rstrip("/")
5357

5458
def set_timeout(self, timeout):
55-
"""Sets the timeout, in seconds, for requests made by the client.
59+
"""Set the timeout in seconds for API requests.
5660
5761
:type timeout: float
5862
"""
@@ -61,9 +65,9 @@ def set_timeout(self, timeout):
6165
self.timeout = timeout
6266

6367
def do(self, method, path, req=None, auth=False):
64-
"""Performs an API request and returns the response.
68+
"""Perform an API request and return the response.
6569
66-
TODO: Handle 429s
70+
TODO: Handle 429s.
6771
6872
:type method: str
6973
:type path: str
@@ -76,7 +80,8 @@ def do(self, method, path, req=None, auth=False):
7680
try:
7781
params = json.loads(json.dumps(req))
7882
except TypeError as e:
79-
raise TypeError("luno: request parameters must be JSON-serializable: %s" % str(e)) from e
83+
msg = "luno: request parameters must be JSON-serializable: %s"
84+
raise TypeError(msg % str(e)) from e
8085
headers = {"User-Agent": self.make_user_agent()}
8186
args = dict(timeout=self.timeout, params=params, headers=headers)
8287
if auth:
@@ -92,7 +97,8 @@ def do(self, method, path, req=None, auth=False):
9297
raise Exception("luno: unknown API error (%s)" % res.status_code)
9398

9499
def make_url(self, path, params):
95-
"""
100+
"""Construct the full URL for an API request.
101+
96102
:type path: str
97103
:rtype: str
98104
"""
@@ -102,7 +108,8 @@ def make_url(self, path, params):
102108
return self.base_url + "/" + path.lstrip("/")
103109

104110
def make_user_agent(self):
105-
"""
111+
"""Generate the User-Agent string for API requests.
112+
106113
:rtype: str
107114
"""
108115
return f"LunoPythonSDK/{VERSION} python/{PYTHON_VERSION} {SYSTEM} {ARCH}"

0 commit comments

Comments
 (0)