1212T = TypeVar ('T' )
1313
1414
15+ def ignore_docs (method : T ) -> T :
16+ """Mark that a method's documentation should not be rendered. Functionally, this decorator is a noop."""
17+ return method
18+
19+
20+ @ignore_docs
1521def filter_out_none_values_recursively (dictionary : Dict ) -> Dict :
1622 """Return copy of the dictionary, recursively omitting all keys for which values are None."""
1723 return cast (dict , _filter_out_none_values_recursively_internal (dictionary ))
1824
1925
26+ @ignore_docs
2027def _filter_out_none_values_recursively_internal (
2128 dictionary : Dict ,
2229 remove_empty_dicts : Optional [bool ] = None ,
@@ -37,26 +44,25 @@ def _filter_out_none_values_recursively_internal(
3744 return result
3845
3946
40- def ignore_docs (method : T ) -> T :
41- """Mark that a method's documentation should not be rendered. Functionally, this decorator is a noop."""
42- return method
43-
44-
47+ @ignore_docs
4548def is_content_type_json (content_type : str ) -> bool :
4649 """Check if the given content type is JSON."""
4750 return bool (re .search (r'^application/json' , content_type , flags = re .IGNORECASE ))
4851
4952
53+ @ignore_docs
5054def is_content_type_xml (content_type : str ) -> bool :
5155 """Check if the given content type is XML."""
5256 return bool (re .search (r'^application/.*xml$' , content_type , flags = re .IGNORECASE ))
5357
5458
59+ @ignore_docs
5560def is_content_type_text (content_type : str ) -> bool :
5661 """Check if the given content type is text."""
5762 return bool (re .search (r'^text/' , content_type , flags = re .IGNORECASE ))
5863
5964
65+ @ignore_docs
6066def is_file_or_bytes (value : Any ) -> bool :
6167 """Check if the input value is a file-like object or bytes.
6268
@@ -67,18 +73,21 @@ def is_file_or_bytes(value: Any) -> bool:
6773 return isinstance (value , (bytes , bytearray , io .IOBase ))
6874
6975
76+ @ignore_docs
7077def json_dumps (obj : Any ) -> str :
7178 """Dump JSON to a string with the correct settings and serializer."""
7279 return json .dumps (obj , ensure_ascii = False , indent = 2 , default = str )
7380
7481
82+ @ignore_docs
7583def maybe_extract_enum_member_value (maybe_enum_member : Any ) -> Any :
7684 """Extract the value of an enumeration member if it is an Enum, otherwise return the original value."""
7785 if isinstance (maybe_enum_member , Enum ):
7886 return maybe_enum_member .value
7987 return maybe_enum_member
8088
8189
90+ @ignore_docs
8291def parse_date_fields (data : ListOrDict , max_depth : int = PARSE_DATE_FIELDS_MAX_DEPTH ) -> ListOrDict :
8392 """Recursively parse date fields in a list or dictionary up to the specified depth."""
8493 if max_depth < 0 :
@@ -98,7 +107,7 @@ def parse(key: str, value: object) -> object:
98107 elif isinstance (value , dict ):
99108 parsed_value = parse_date_fields (value , max_depth - 1 )
100109 elif isinstance (value , list ):
101- parsed_value = parse_date_fields (value , max_depth )
110+ parsed_value = parse_date_fields (value , max_depth ) # type: ignore # mypy doesn't work with decorators and recursive calls well
102111 return parsed_value
103112
104113 return {key : parse (key , value ) for (key , value ) in data .items ()}
0 commit comments