12
12
T = TypeVar ('T' )
13
13
14
14
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
15
21
def filter_out_none_values_recursively (dictionary : Dict ) -> Dict :
16
22
"""Return copy of the dictionary, recursively omitting all keys for which values are None."""
17
23
return cast (dict , _filter_out_none_values_recursively_internal (dictionary ))
18
24
19
25
26
+ @ignore_docs
20
27
def _filter_out_none_values_recursively_internal (
21
28
dictionary : Dict ,
22
29
remove_empty_dicts : Optional [bool ] = None ,
@@ -37,26 +44,25 @@ def _filter_out_none_values_recursively_internal(
37
44
return result
38
45
39
46
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
45
48
def is_content_type_json (content_type : str ) -> bool :
46
49
"""Check if the given content type is JSON."""
47
50
return bool (re .search (r'^application/json' , content_type , flags = re .IGNORECASE ))
48
51
49
52
53
+ @ignore_docs
50
54
def is_content_type_xml (content_type : str ) -> bool :
51
55
"""Check if the given content type is XML."""
52
56
return bool (re .search (r'^application/.*xml$' , content_type , flags = re .IGNORECASE ))
53
57
54
58
59
+ @ignore_docs
55
60
def is_content_type_text (content_type : str ) -> bool :
56
61
"""Check if the given content type is text."""
57
62
return bool (re .search (r'^text/' , content_type , flags = re .IGNORECASE ))
58
63
59
64
65
+ @ignore_docs
60
66
def is_file_or_bytes (value : Any ) -> bool :
61
67
"""Check if the input value is a file-like object or bytes.
62
68
@@ -67,18 +73,21 @@ def is_file_or_bytes(value: Any) -> bool:
67
73
return isinstance (value , (bytes , bytearray , io .IOBase ))
68
74
69
75
76
+ @ignore_docs
70
77
def json_dumps (obj : Any ) -> str :
71
78
"""Dump JSON to a string with the correct settings and serializer."""
72
79
return json .dumps (obj , ensure_ascii = False , indent = 2 , default = str )
73
80
74
81
82
+ @ignore_docs
75
83
def maybe_extract_enum_member_value (maybe_enum_member : Any ) -> Any :
76
84
"""Extract the value of an enumeration member if it is an Enum, otherwise return the original value."""
77
85
if isinstance (maybe_enum_member , Enum ):
78
86
return maybe_enum_member .value
79
87
return maybe_enum_member
80
88
81
89
90
+ @ignore_docs
82
91
def parse_date_fields (data : ListOrDict , max_depth : int = PARSE_DATE_FIELDS_MAX_DEPTH ) -> ListOrDict :
83
92
"""Recursively parse date fields in a list or dictionary up to the specified depth."""
84
93
if max_depth < 0 :
@@ -98,7 +107,7 @@ def parse(key: str, value: object) -> object:
98
107
elif isinstance (value , dict ):
99
108
parsed_value = parse_date_fields (value , max_depth - 1 )
100
109
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
102
111
return parsed_value
103
112
104
113
return {key : parse (key , value ) for (key , value ) in data .items ()}
0 commit comments