MCPcopy
hub / github.com/psf/requests / merge_setting

Function merge_setting

src/requests/sessions.py:76–105  ·  view source on GitHub ↗

Determines appropriate setting for a given request, taking into account the explicit setting on that request, and the setting in the session. If a setting is a dictionary, they will be merged together using `dict_class`

(
    request_setting: Any, session_setting: Any, dict_class: type = OrderedDict
)

Source from the content-addressed store, hash-verified

74
75
76def merge_setting(
77 request_setting: Any, session_setting: Any, dict_class: type = OrderedDict
78) -> Any:
79 """Determines appropriate setting for a given request, taking into account
80 the explicit setting on that request, and the setting in the session. If a
81 setting is a dictionary, they will be merged together using `dict_class`
82 """
83
84 if session_setting is None:
85 return request_setting
86
87 if request_setting is None:
88 return session_setting
89
90 # Bypass if not a dictionary (e.g. verify)
91 if not (
92 isinstance(session_setting, Mapping) and isinstance(request_setting, Mapping)
93 ):
94 return request_setting
95
96 merged_setting = dict_class(to_key_val_list(session_setting)) # type: ignore[arg-type] # isinstance narrows Any to Mapping[Unknown]
97 merged_setting.update(to_key_val_list(request_setting)) # type: ignore[arg-type]
98
99 # Remove keys that are set to None. Extract keys first to avoid altering
100 # the dictionary during iteration.
101 none_keys = [k for (k, v) in merged_setting.items() if v is None]
102 for key in none_keys:
103 del merged_setting[key]
104
105 return merged_setting
106
107
108def merge_hooks(

Callers 3

merge_hooksFunction · 0.85
prepare_requestMethod · 0.85

Calls 3

to_key_val_listFunction · 0.85
updateMethod · 0.80
itemsMethod · 0.45

Tested by

no test coverage detected