Skip to content

Commit afa065c

Browse files
committed
Static typing
1 parent f2171fd commit afa065c

File tree

1 file changed

+27
-14
lines changed

1 file changed

+27
-14
lines changed

muckrock/__init__.py

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ def __init__(self, token: str | None = None, base_uri: str | None = None):
1919
"""Create a new client object."""
2020
self.BASE_URI = base_uri or BaseMuckRockClient.BASE_URI
2121
if token:
22-
self.token = token
22+
self.token: str | None = token
2323
else:
24-
if os.getenv("MUCKROCK_API_TOKEN"):
25-
self.token = os.getenv("MUCKROCK_API_TOKEN")
26-
else:
27-
self.token = None
24+
self.token = os.getenv("MUCKROCK_API_TOKEN") or None
2825

29-
def _get_request(self, url: str, params: dict | None = None, headers: dict | None = None) -> Any:
26+
def _get_request(
27+
self, url: str, params: dict | None = None, headers: dict | None = None
28+
) -> Any:
3029
"""Make a GET request to the Muckrock API.
3130
3231
Returns the response as JSON.
@@ -50,7 +49,9 @@ def _get_request(self, url: str, params: dict | None = None, headers: dict | Non
5049
)
5150
return response.json()
5251

53-
def _post_request(self, url: str, data: dict | None = None, headers: dict | None = None) -> Any:
52+
def _post_request(
53+
self, url: str, data: dict | None = None, headers: dict | None = None
54+
) -> Any:
5455
"""Make a GET request to the Muckrock API.
5556
5657
Returns the response as JSON.
@@ -84,7 +85,13 @@ def _post_request(self, url: str, data: dict | None = None, headers: dict | None
8485
class MuckRock(BaseMuckRockClient):
8586
"""The public interface for the DocumentCloud API."""
8687

87-
def __init__(self, username: str | None = None, password: str | None = None, token: str | None = None, base_uri: str | None = None):
88+
def __init__(
89+
self,
90+
username: str | None = None,
91+
password: str | None = None,
92+
token: str | None = None,
93+
base_uri: str | None = None,
94+
):
8895
"""Create an object."""
8996
# Set all the basic configuration options to this, the parent instance.
9097
super().__init__(token, base_uri)
@@ -99,7 +106,7 @@ def __init__(self, username: str | None = None, password: str | None = None, tok
99106
class BaseEndpointMixin:
100107
"""Methods shared by endpoint classes."""
101108

102-
def get(self, id: str | int):
109+
def get(self, id):
103110
"""Return a request with the specified identifer."""
104111
url = self.BASE_URI + self.endpoint + f"/{id}/"
105112
r = self._get_request(url)
@@ -122,7 +129,7 @@ def filter(
122129
requires_proxy: bool | None = None,
123130
) -> Any:
124131
"""Return a list of requests that match the provide input filters."""
125-
params = {}
132+
params: dict[str, Any] = {}
126133
if name:
127134
params["name"] = name
128135
if abbreviation:
@@ -146,9 +153,15 @@ class AgencyEndpoint(BaseMuckRockClient, BaseEndpointMixin):
146153

147154
endpoint = "agency"
148155

149-
def filter(self, name: str | None = None, status: str | None = None, jurisdiction_id: str | int | None = None, requires_proxy: bool | None = None) -> Any:
156+
def filter(
157+
self,
158+
name: str | None = None,
159+
status: str | None = None,
160+
jurisdiction_id: str | int | None = None,
161+
requires_proxy: bool | None = None,
162+
) -> Any:
150163
"""Return a list of requests that match the provide input filters."""
151-
params = {}
164+
params: dict[str, Any] = {}
152165
if name:
153166
params["name"] = name
154167
if status:
@@ -214,10 +227,10 @@ def filter(
214227
agency_id: str | int | None = None,
215228
has_datetime_submitted: bool | None = None,
216229
has_datetime_done: bool | None = None,
217-
ordering: str ="-datetime_submitted",
230+
ordering: str = "-datetime_submitted",
218231
) -> Any:
219232
"""Return a list of requests that match the provide input filters."""
220-
params = {}
233+
params: dict[str, Any] = {}
221234
if user:
222235
params["user"] = user
223236
if title:

0 commit comments

Comments
 (0)