Skip to content

Commit fc04f2a

Browse files
author
Paul Duncan
committed
line-length set to 120
1 parent c2fb833 commit fc04f2a

26 files changed

+136
-445
lines changed

predicthq/client.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ def get_headers(self, headers):
5555
@stamina.retry(on=RetriableError, attempts=3)
5656
def request(self, method, path, **kwargs):
5757
headers = self.get_headers(kwargs.pop("headers", {}))
58-
response = requests.request(
59-
method, self.build_url(path), headers=headers, **kwargs
60-
)
58+
response = requests.request(method, self.build_url(path), headers=headers, **kwargs)
6159
self.logger.debug(response.request.url)
6260
try:
6361
response.raise_for_status()

predicthq/endpoints/base.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ def for_account(self, account_id):
3535

3636
def build_url(self, prefix, suffix):
3737
if self.account_id is not None:
38-
return (
39-
f"/{prefix.strip('/')}/accounts/{self.account_id}/{suffix.strip('/')}/"
40-
)
38+
return f"/{prefix.strip('/')}/accounts/{self.account_id}/{suffix.strip('/')}/"
4139
else:
4240
return super(UserBaseEndpoint, self).build_url(prefix, suffix)

predicthq/endpoints/v1/events/schemas.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,7 @@ class Event(BaseModel):
114114
private: Optional[bool] = None # Loop add-on
115115
rank: Optional[int] = None # PHQ Rank add-on
116116
predicted_event_spend: Optional[int] = None # Predicted Event Spend add-on
117-
predicted_event_spend_industries: Optional[PredictedEventSpendIndustries] = (
118-
None # Predicted Event Spend add-on
119-
)
117+
predicted_event_spend_industries: Optional[PredictedEventSpendIndustries] = None # Predicted Event Spend add-on
120118

121119

122120
class EventResultSet(ResultSet):

predicthq/endpoints/v1/features/endpoint.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class FeaturesEndpoint(UserBaseEndpoint):
1919
def mutate_bool_to_default_for_type(cls, user_request_spec):
2020
for key, val in user_request_spec.items():
2121
if any(key.startswith(x) for x in cls.FIELDS_TO_MUTATE):
22-
user_request_spec[key] = [
23-
cls.BASE_FEATURE_CRITERIA if isinstance(v, bool) else v for v in val
24-
]
22+
user_request_spec[key] = [cls.BASE_FEATURE_CRITERIA if isinstance(v, bool) else v for v in val]
2523

2624
@accepts(query_string=False)
2725
@returns(FeatureResultSet)

predicthq/endpoints/v1/features/schemas.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,12 @@ def __flatten_json(d: dict, pk: str = "") -> dict:
1313
flat_json = {}
1414
for k, v in d.items():
1515
if isinstance(v, dict):
16-
flat_json.update(
17-
__flatten_json(v, f"{pk}{separator}{k}" if pk else k)
18-
)
16+
flat_json.update(__flatten_json(v, f"{pk}{separator}{k}" if pk else k))
1917
continue
2018
flat_json.update({f"{pk}{separator}{k}" if pk else k: v})
2119
return flat_json
2220

23-
return [
24-
__flatten_json(d.model_dump(exclude_none=True)) for d in self.iter_all()
25-
]
21+
return [__flatten_json(d.model_dump(exclude_none=True)) for d in self.iter_all()]
2622

2723
def to_csv(self, file: str, mode: str = "w+", separator: str = "_") -> None:
2824
header = None
@@ -67,6 +63,4 @@ def get_next(self):
6763
if not self.has_next() or not hasattr(self, "_more"):
6864
return
6965
params = self._parse_params(self.next)
70-
return self._more(
71-
_params=params, _json=self._kwargs.get("_json", {}) or self._kwargs
72-
)
66+
return self._more(_params=params, _json=self._kwargs.get("_json", {}) or self._kwargs)

predicthq/endpoints/v1/saved_locations/schemas.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,7 @@ class SavedLocation(SavedLocationBase):
210210
enrich_dt: Optional[datetime] = None
211211
insights_dt: Optional[datetime] = None
212212
user_id: Optional[str] = None
213-
subscription_valid_types: Annotated[
214-
List[SubscriptionValidType], Field(default_factory=list)
215-
]
213+
subscription_valid_types: Annotated[List[SubscriptionValidType], Field(default_factory=list)]
216214
status: SavedLocationStatus
217215
summary_insights: Annotated[List[SummaryInsights], Field(default_factory=list)]
218216
places: Annotated[List[Place], Field(default_factory=list)]

setup.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def read(*parts):
2121

2222

2323
REPO_URL = "https://github.com/predicthq/sdk-py"
24-
PYPI_README_NOTE = f"For the latest source, discussions, bug reports, etc., please visit the [GitHub repository]({REPO_URL})"
24+
PYPI_README_NOTE = (
25+
f"For the latest source, discussions, bug reports, etc., please visit the [GitHub repository]({REPO_URL})"
26+
)
2527
LONG_DESCRIPTION = "\n\n".join([PYPI_README_NOTE, read("README.md")])
2628

2729

tests/__init__.py

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ def decorator(f):
3333
@functools.wraps(f)
3434
def wrapper(*args, **kwargs):
3535
class_name, func_name = (
36-
re.sub(r"([A-Z]+)", r"_\1", args[0].__class__.__name__)
37-
.lower()
38-
.strip("_"),
36+
re.sub(r"([A-Z]+)", r"_\1", args[0].__class__.__name__).lower().strip("_"),
3937
f.__name__,
4038
)
4139
fixtures = load_reqresp_fixture(req_resp or f"{class_name}/{func_name}")
@@ -46,10 +44,7 @@ def wrapper(*args, **kwargs):
4644
fixture["url"] = re.compile(Client.build_url(url_re))
4745
else:
4846
fixture["url"] = Client.build_url(fixture["url"])
49-
if (
50-
"content_type" in fixture
51-
and fixture["content_type"] == "application/json"
52-
):
47+
if "content_type" in fixture and fixture["content_type"] == "application/json":
5348
fixture["body"] = json.dumps(fixture["body"])
5449
rsps.add(**fixture)
5550
return f(responses=rsps, *args, **kwargs)
@@ -81,9 +76,7 @@ def wrapper(*args, **kwargs):
8176
return decorator
8277

8378

84-
def with_mock_client(
85-
request_returns=None, request_raises=None, *client_args, **client_kwargs
86-
):
79+
def with_mock_client(request_returns=None, request_raises=None, *client_args, **client_kwargs):
8780
def decorator(f):
8881
@functools.wraps(f)
8982
def wrapper(*args, **kwargs):

tests/endpoints/test_decorators.py

Lines changed: 14 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,11 @@ def func(self, *args, **kwargs):
110110
assert transformed_kwargs == {"arg1": "test", "arg2": "1,2"}
111111
assert transformed_args == ()
112112

113-
transformed_args, transformed_kwargs = endpoint.func(
114-
**{"arg1": "test", "arg2": [1, 2]}
115-
)
113+
transformed_args, transformed_kwargs = endpoint.func(**{"arg1": "test", "arg2": [1, 2]})
116114
assert transformed_kwargs == {"arg1": "test", "arg2": "1,2"}
117115
assert transformed_args == ()
118116

119-
transformed_args, transformed_kwargs = endpoint.func(
120-
{"arg1": "test", "arg2": [1, 2]}
121-
)
117+
transformed_args, transformed_kwargs = endpoint.func({"arg1": "test", "arg2": [1, 2]})
122118
assert transformed_kwargs == {}
123119
assert transformed_args == ({"arg1": "test", "arg2": [1, 2]},)
124120

@@ -134,9 +130,9 @@ def func(self, **kwargs):
134130
return kwargs
135131

136132
endpoint = EndpointExample(None)
137-
assert endpoint.func(arg1="test", arg2=[1, 2]).model_dump(
138-
exclude_none=True
139-
) == SchemaExample(**{"arg1": "test", "arg2": [1, 2]}).model_dump(exclude_none=True)
133+
assert endpoint.func(arg1="test", arg2=[1, 2]).model_dump(exclude_none=True) == SchemaExample(
134+
**{"arg1": "test", "arg2": [1, 2]}
135+
).model_dump(exclude_none=True)
140136

141137
with pytest.raises(ValidationError):
142138
endpoint.func(arg2=[1, 2])
@@ -155,12 +151,12 @@ def func(self, **kwargs):
155151
return kwargs
156152

157153
endpoint = EndpointExample(None)
158-
assert endpoint.func(results=["item1", "item2"]).model_dump(
159-
exclude_none=True
160-
) == SchemaExample(**{"results": ["item1", "item2"]}).model_dump(exclude_none=True)
161-
assert endpoint.func()._more(results=["item3", "item4"]).model_dump(
162-
exclude_none=True
163-
) == SchemaExample(**{"results": ["item3", "item4"]}).model_dump(exclude_none=True)
154+
assert endpoint.func(results=["item1", "item2"]).model_dump(exclude_none=True) == SchemaExample(
155+
**{"results": ["item1", "item2"]}
156+
).model_dump(exclude_none=True)
157+
assert endpoint.func()._more(results=["item3", "item4"]).model_dump(exclude_none=True) == SchemaExample(
158+
**{"results": ["item3", "item4"]}
159+
).model_dump(exclude_none=True)
164160
assert endpoint == endpoint.func()._endpoint
165161

166162

@@ -181,8 +177,6 @@ def func(self, **kwargs):
181177
assert results.model_dump(exclude_none=True) == SchemaExample(
182178
**{"results": [{"name": "item1"}, {"name": "item2"}]}
183179
).model_dump(exclude_none=True)
184-
assert endpoint.func()._more(
185-
results=[{"name": "item2"}, {"name": "item4"}]
186-
).model_dump(exclude_none=True) == SchemaExample(
187-
**{"results": [{"name": "item2"}, {"name": "item4"}]}
188-
).model_dump(exclude_none=True)
180+
assert endpoint.func()._more(results=[{"name": "item2"}, {"name": "item4"}]).model_dump(
181+
exclude_none=True
182+
) == SchemaExample(**{"results": [{"name": "item2"}, {"name": "item4"}]}).model_dump(exclude_none=True)

tests/endpoints/test_oauth2.py

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def test_get_token_params_without_ssl_verification(self, client):
4343

4444
@with_mock_client()
4545
def test_revoke_token_params(self, client):
46-
result = client.oauth2.revoke_token(
47-
client_id="client_id", client_secret="client_secret", token="token123"
48-
)
46+
result = client.oauth2.revoke_token(client_id="client_id", client_secret="client_secret", token="token123")
4947
client.request.assert_called_once_with(
5048
"post",
5149
"/oauth2/revoke/",
@@ -84,14 +82,8 @@ def test_get_token(self, client, responses):
8482
assert token.token_type == "Bearer"
8583
assert token.scope == ["account", "events"]
8684
assert len(responses.calls) == 1
87-
assert (
88-
responses.calls[0].request.headers["Content-Type"]
89-
== "application/x-www-form-urlencoded"
90-
)
91-
assert (
92-
responses.calls[0].request.headers["Authorization"]
93-
== "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
94-
)
85+
assert responses.calls[0].request.headers["Content-Type"] == "application/x-www-form-urlencoded"
86+
assert responses.calls[0].request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
9587
assert dict(parse_qsl(responses.calls[0].request.body)) == {
9688
"scope": "account events",
9789
"grant_type": "client_credentials",
@@ -100,19 +92,11 @@ def test_get_token(self, client, responses):
10092
@with_client()
10193
@with_mock_responses()
10294
def test_revoke_token(self, client, responses):
103-
result = client.oauth2.revoke_token(
104-
client_id="client_id", client_secret="client_secret", token="token123"
105-
)
95+
result = client.oauth2.revoke_token(client_id="client_id", client_secret="client_secret", token="token123")
10696
assert result is None
10797
assert len(responses.calls) == 1
108-
assert (
109-
responses.calls[0].request.headers["Content-Type"]
110-
== "application/x-www-form-urlencoded"
111-
)
112-
assert (
113-
responses.calls[0].request.headers["Authorization"]
114-
== "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
115-
)
98+
assert responses.calls[0].request.headers["Content-Type"] == "application/x-www-form-urlencoded"
99+
assert responses.calls[0].request.headers["Authorization"] == "Basic Y2xpZW50X2lkOmNsaWVudF9zZWNyZXQ="
116100
assert dict(parse_qsl(responses.calls[0].request.body)) == {
117101
"token_type_hint": "access_token",
118102
"token": "token123",
@@ -137,9 +121,7 @@ def test_oauth2_endpoint_method_deprecation_warning(self):
137121
except Exception:
138122
pass # Ignore errors from None client
139123
assert any(
140-
issubclass(warning.category, FutureWarning)
141-
and expected_text in str(warning.message)
142-
for warning in w
124+
issubclass(warning.category, FutureWarning) and expected_text in str(warning.message) for warning in w
143125
)
144126

145127
# Test revoke_token
@@ -150,7 +132,5 @@ def test_oauth2_endpoint_method_deprecation_warning(self):
150132
except Exception:
151133
pass # Ignore errors from None client
152134
assert any(
153-
issubclass(warning.category, FutureWarning)
154-
and expected_text in str(warning.message)
155-
for warning in w
135+
issubclass(warning.category, FutureWarning) and expected_text in str(warning.message) for warning in w
156136
)

0 commit comments

Comments
 (0)