Skip to content

Commit f2171fd

Browse files
committed
Static typing
1 parent 93f9f06 commit f2171fd

File tree

1 file changed

+34
-31
lines changed

1 file changed

+34
-31
lines changed

muckrock/__init__.py

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
"""A simple python wrapper for the [MuckRock API."""
2+
from __future__ import annotations
3+
24
import os
5+
from typing import Any
36

47
import requests
58

@@ -12,7 +15,7 @@ class BaseMuckRockClient:
1215
BASE_URI = "https://www.muckrock.com/api_v1/"
1316
USER_AGENT = "python-muckrock (https://github.com/palewire/python-muckrock)"
1417

15-
def __init__(self, token=None, base_uri=None):
18+
def __init__(self, token: str | None = None, base_uri: str | None = None):
1619
"""Create a new client object."""
1720
self.BASE_URI = base_uri or BaseMuckRockClient.BASE_URI
1821
if token:
@@ -23,7 +26,7 @@ def __init__(self, token=None, base_uri=None):
2326
else:
2427
self.token = None
2528

26-
def _get_request(self, url, params=None, headers=None):
29+
def _get_request(self, url: str, params: dict | None = None, headers: dict | None = None) -> Any:
2730
"""Make a GET request to the Muckrock API.
2831
2932
Returns the response as JSON.
@@ -47,7 +50,7 @@ def _get_request(self, url, params=None, headers=None):
4750
)
4851
return response.json()
4952

50-
def _post_request(self, url, data=None, headers=None):
53+
def _post_request(self, url: str, data: dict | None = None, headers: dict | None = None) -> Any:
5154
"""Make a GET request to the Muckrock API.
5255
5356
Returns the response as JSON.
@@ -81,7 +84,7 @@ def _post_request(self, url, data=None, headers=None):
8184
class MuckRock(BaseMuckRockClient):
8285
"""The public interface for the DocumentCloud API."""
8386

84-
def __init__(self, username=None, password=None, token=None, base_uri=None):
87+
def __init__(self, username: str | None = None, password: str | None = None, token: str | None = None, base_uri: str | None = None):
8588
"""Create an object."""
8689
# Set all the basic configuration options to this, the parent instance.
8790
super().__init__(token, base_uri)
@@ -96,7 +99,7 @@ def __init__(self, username=None, password=None, token=None, base_uri=None):
9699
class BaseEndpointMixin:
97100
"""Methods shared by endpoint classes."""
98101

99-
def get(self, id):
102+
def get(self, id: str | int):
100103
"""Return a request with the specified identifer."""
101104
url = self.BASE_URI + self.endpoint + f"/{id}/"
102105
r = self._get_request(url)
@@ -112,12 +115,12 @@ class JurisdictionEndpoint(BaseMuckRockClient, BaseEndpointMixin):
112115

113116
def filter(
114117
self,
115-
name=None,
116-
abbreviation=None,
117-
parent_id=None,
118-
level=None,
119-
requires_proxy=None,
120-
):
118+
name: str | None = None,
119+
abbreviation: str | None = None,
120+
parent_id: str | int | None = None,
121+
level: str | None = None,
122+
requires_proxy: bool | None = None,
123+
) -> Any:
121124
"""Return a list of requests that match the provide input filters."""
122125
params = {}
123126
if name:
@@ -143,7 +146,7 @@ class AgencyEndpoint(BaseMuckRockClient, BaseEndpointMixin):
143146

144147
endpoint = "agency"
145148

146-
def filter(self, name=None, status=None, jurisdiction_id=None, requires_proxy=None):
149+
def filter(self, name: str | None = None, status: str | None = None, jurisdiction_id: str | int | None = None, requires_proxy: bool | None = None) -> Any:
147150
"""Return a list of requests that match the provide input filters."""
148151
params = {}
149152
if name:
@@ -168,15 +171,15 @@ class FoiaEndpoint(BaseMuckRockClient, BaseEndpointMixin):
168171

169172
def create(
170173
self,
171-
title="",
172-
document_request="",
173-
full_text="",
174-
agency_ids=None,
175-
embargo=False,
176-
permanent_embargo=False,
177-
attachments=None,
178-
organization=None,
179-
):
174+
title: str = "",
175+
document_request: str = "",
176+
full_text: str = "",
177+
agency_ids: list[str | int] | None = None,
178+
embargo: bool = False,
179+
permanent_embargo: bool = False,
180+
attachments: Any | None = None,
181+
organization: str | int | None = None,
182+
) -> Any:
180183
"""Create a new request."""
181184
if not title:
182185
raise TypeError("title kwarg required")
@@ -203,16 +206,16 @@ def create(
203206

204207
def filter(
205208
self,
206-
user=None,
207-
title=None,
208-
status=None,
209-
embargo=None,
210-
jurisdiction_id=None,
211-
agency_id=None,
212-
has_datetime_submitted=None,
213-
has_datetime_done=None,
214-
ordering="-datetime_submitted",
215-
):
209+
user: str | None = None,
210+
title: str | None = None,
211+
status: str | None = None,
212+
embargo: str | None = None,
213+
jurisdiction_id: str | int | None = None,
214+
agency_id: str | int | None = None,
215+
has_datetime_submitted: bool | None = None,
216+
has_datetime_done: bool | None = None,
217+
ordering: str ="-datetime_submitted",
218+
) -> Any:
216219
"""Return a list of requests that match the provide input filters."""
217220
params = {}
218221
if user:

0 commit comments

Comments
 (0)