dataclass-rest icon indicating copy to clipboard operation
dataclass-rest copied to clipboard

mypy reports missing required arguments for `RestBuilder` when using keyword arguments

Open anmayithap opened this issue 1 year ago • 1 comments

Bug

When creating a RestBuilder instance with only some of the optional parameters, mypy reports missing required arguments:

Missing named argument "body_name" for "RestBuilder"
Missing named argument "query_param_dumper" for "RestBuilder"
Missing named argument "query_param_post_dump" for "RestBuilder"
Missing named argument "error_raiser" for "RestBuilder"

Root cause

The BuilderParams TypedDict is defined without NotRequired (or total=False), so mypy treats all fields as required when unpacked via **params: Unpack[BuilderParams].

Fix

Mark all optional fields with NotRequired:

class BuilderParams(TypedDict):
    body_name: NotRequired[str]

    query_param_dumper: NotRequired[Dumper | None]
    request_body_dumper: NotRequired[Dumper | None]
    request_body_post_dump: NotRequired[RequestTransformer | None]
    query_param_post_dump: NotRequired[RequestTransformer | None]

    response_body_loader: NotRequired[Loader | None]
    response_body_pre_load: NotRequired[ResponseTransformer | None]
    error_raiser: NotRequired[ResponseTransformer | None]

Alternatively, define the TypedDict with total=False and mark only truly required fields (if any). After this change, mypy correctly recognizes the parameters as optional and the errors disappear.

Environment

mypy 1.18 (strict mode) Python 3.13

Ready to send a PR if needed

anmayithap avatar Dec 02 '25 13:12 anmayithap

Thanks. It is definitely a bug introduced in latest version:

https://github.com/reagento/descanso/pull/82/files#diff-76b3c3ad20dbb4724eaed88a552b3c5a0fc8d6fe6ef963283252af679073fc50L71

Can you prepare a PR containing fix using total=False?

Tishka17 avatar Dec 02 '25 13:12 Tishka17