Skip to content

Commit a4d69b5

Browse files
Fix mypy strict type-checking errors
- Add type parameters to bare dict returns (facilitator, lineage, routes) - Cast response.body to bytes to resolve bytes|memoryview union - Use separate variables for PlainTextResponse/JSONResponse branches to avoid incompatible assignment types
1 parent 0d8d06c commit a4d69b5

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

api/routes.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,16 @@ async def fetch_content(
132132
grant_header = await _issue_grant_for_response(request, result.markdown, url, license_type)
133133

134134
if content_format == ContentFormat.MARKDOWN:
135-
response = PlainTextResponse(result.markdown, media_type="text/markdown")
135+
md_response = PlainTextResponse(result.markdown, media_type="text/markdown")
136136
_attach_compliance_headers(
137-
response,
137+
md_response,
138138
signer=signer,
139139
content=result.markdown,
140140
license_type=license_type,
141141
license_id=grant_header,
142142
)
143-
_attach_preferred_access(response, request)
144-
return response
143+
_attach_preferred_access(md_response, request)
144+
return md_response
145145

146146
summary_result = await summarizer.summarize(result.markdown)
147147
tracker.record(
@@ -166,19 +166,19 @@ async def fetch_content(
166166
if grant_header:
167167
body["fairfetch:usageGrant"] = grant_header
168168
media = content_format.value
169-
response = JSONResponse(content=body, media_type=media)
169+
json_response = JSONResponse(content=body, media_type=media)
170170
else:
171-
response = JSONResponse(content=packet.to_jsonld())
171+
json_response = JSONResponse(content=packet.to_jsonld())
172172

173173
_attach_compliance_headers(
174-
response,
174+
json_response,
175175
signer=signer,
176176
content=result.markdown,
177177
license_type=license_type,
178178
license_id=grant_header,
179179
)
180-
_attach_preferred_access(response, request)
181-
return response
180+
_attach_preferred_access(json_response, request)
181+
return json_response
182182

183183

184184
@router.get("/content/summary")
@@ -229,7 +229,7 @@ async def get_markdown(
229229

230230

231231
@router.get("/health")
232-
async def health(request: Request) -> dict:
232+
async def health(request: Request) -> dict[str, object]:
233233
scraper_count = getattr(request.app.state, "scraper_intercept_count", 0)
234234
return {
235235
"status": "ok",

compliance/lineage.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def record(
6464
)
6565
)
6666

67-
def to_dict(self) -> dict:
67+
def to_dict(self) -> dict[str, object]:
6868
return {
6969
"source_url": self._source_url,
7070
"pipeline": [r.model_dump() for r in self._records],

interfaces/facilitator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class PaymentRequirement(BaseModel):
3434
description: str = Field(default="Content access fee")
3535
extra: dict[str, str] = Field(default_factory=dict)
3636

37-
def to_402_body(self) -> dict:
37+
def to_402_body(self) -> dict[str, object]:
3838
return {
3939
"accepts": {
4040
"price": self.price,

payments/x402.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ async def dispatch(self, request: Request, call_next: RequestResponseEndpoint) -
8383
if self._license_provider:
8484
body_bytes = b""
8585
if hasattr(response, "body"):
86-
body_bytes = response.body
86+
body_bytes = bytes(response.body)
8787
content_hash = hashlib.sha256(body_bytes).hexdigest() if body_bytes else ""
8888

8989
url_param = request.query_params.get("url", request.url.path)

0 commit comments

Comments
 (0)