# -*- coding: utf-8 -*-"""Argument manipulation utilities.This module provides utilities for handling required and optional parametersin the context of HTTP API requests and dataclass constructors. It definessentinel values and helper functions to:1. Mark parameters as explicitly required (:attr:`REQ`)2. Mark parameters as explicitly "Not Applicable" (:attr:`NA`) rather than using None3. Remove ``NA`` values from kwargs before sending to HTTP APIsThe sentinel values REQ and NA help maintain proper dataclass field orderingsince dataclasses don't allow required fields (those without defaults) to bedefined after fields with default values. By using these sentinels, we candefine required and optional fields in any order without worrying aboutdataclass constraints.When mapping Python function arguments to HTTP request parameters, the rm_nafunction can be called to remove all NA values from the keyword argumentsdictionary before sending the request."""importdataclassesfrom.type_hintimportT_KWARGS@dataclasses.dataclass(frozen=True)class_REQUIRED:def__eq__(self,other):returnisinstance(other,_REQUIRED)REQ=_REQUIRED()@dataclasses.dataclass(frozen=True)class_NOTHING:def__eq__(self,other):print(self,other)returnisinstance(other,_NOTHING)NA=_NOTHING()
[docs]defrm_na(**kwargs)->T_KWARGS:""" 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} """return{key:valueforkey,valueinkwargs.items()ifisinstance(value,_NOTHING)isFalse}