arg¶
Argument manipulation utilities.
This module provides utilities for handling required and optional parameters in the context of HTTP API requests and dataclass constructors. It defines sentinel values and helper functions to:
Mark parameters as explicitly required (
REQ)Mark parameters as explicitly “Not Applicable” (
NA) rather than using NoneRemove
NAvalues from kwargs before sending to HTTP APIs
The sentinel values REQ and NA help maintain proper dataclass field ordering since dataclasses don’t allow required fields (those without defaults) to be defined after fields with default values. By using these sentinels, we can define required and optional fields in any order without worrying about dataclass constraints.
When mapping Python function arguments to HTTP request parameters, the rm_na function can be called to remove all NA values from the keyword arguments dictionary before sending the request.
- pyshortio.arg.rm_na(**kwargs) Dict[str, Any][source]¶
Remove NA values from kwargs.
This function filters out any keyword arguments that have the NA sentinel value. It’s particularly useful when preparing parameters for HTTP API requests where you want to exclude optional parameters that weren’t provided.
Example: >>> params = {“domain_id”: 123, “limit”: 10, “offset”: NA} >>> filtered_params = rm_na(**params) >>> # filtered_params will be {“domain_id”: 123, “limit”: 10}