Skip to content

Commit c8d6e77

Browse files
nickwinderclaude
andcommitted
refactor(client): align parse() style with the rest of the file
Three small style nits surfaced in code review against the patterns set by sign() and the other raw-send_request methods (get_account_info, create_token, delete_token): - Drop the redundant inner cast("ParseOutput", {"format": output_format}). ParseOutput is a single-key TypedDict with total=False; the literal already satisfies it structurally via the surrounding ParseInstructions annotation. No other call site in client.py casts an inner literal this way. - Replace the RequestConfig(...) constructor call with an inline dict literal at the send_request boundary, matching sign / create_token / delete_token / get_account_info. RequestConfig is a generic TypedDict; the constructor form is the outlier. - Broaden the file parameter docstring to call out that the endpoint accepts PDFs, Office documents, and images. Unlike sign(), parsing is not PDF-only, and the previous docstring implicitly invited readers to transplant sign()'s PDF-only mental model. No behavior change. format) combinations. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 90040d6 commit c8d6e77

1 file changed

Lines changed: 13 additions & 10 deletions

File tree

src/nutrient_dws/client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
from nutrient_dws.types.parse import (
5959
ParseInstructions,
6060
ParseMode,
61-
ParseOutput,
6261
ParseOutputFormat,
6362
ParseResponse,
6463
)
@@ -799,7 +798,10 @@ async def parse(
799798
800799
Args:
801800
file: The document to parse (local files only — paths, bytes, or
802-
file-like objects).
801+
file-like objects). The endpoint accepts a range of document
802+
formats (PDF, Office documents, images); see the public
803+
guide for the authoritative list. Unlike `sign()`, parsing
804+
is not restricted to PDFs.
803805
mode: Processing mode. See per-mode credit costs above. Defaults
804806
to `"structure"`.
805807
output_format: Output shape — `"spatial"` for typed elements or
@@ -835,22 +837,23 @@ async def parse(
835837

836838
instructions: ParseInstructions = {
837839
"mode": mode,
838-
"output": cast("ParseOutput", {"format": output_format}),
840+
"output": {"format": output_format},
839841
}
840842

841843
request_data: ParseRequestData = {
842844
"file": normalized_file,
843845
"instructions": instructions,
844846
}
845847

846-
config = RequestConfig(
847-
method="POST",
848-
endpoint="/extraction/parse",
849-
data=request_data,
850-
headers=None,
848+
response: Any = await send_request(
849+
{
850+
"method": "POST",
851+
"endpoint": "/extraction/parse",
852+
"data": request_data,
853+
"headers": None,
854+
},
855+
self.options,
851856
)
852-
853-
response: Any = await send_request(config, self.options)
854857
return cast("ParseResponse", response["data"])
855858

856859
async def set_page_labels(

0 commit comments

Comments
 (0)