pep584ify: use dict merge operator (#10279)

This was introduced in Python 3.9. The change makes
dict merges 'obvious' and looks cleaner.

I haven't changed `.update()` to `|=` (update operator),
as I find the former to be more readable and "obvious".
This commit is contained in:
skshetry
2024-02-03 15:58:07 +05:45
committed by GitHub
parent 68b9ecb95c
commit 2bf7bd990a
13 changed files with 21 additions and 21 deletions
+1 -1
View File
@@ -25,7 +25,7 @@ def _postprocess(results):
(k if counts[k] == 1 else f"{file_name}:{k}"): v
for k, v in file_data["data"].items()
}
processed[rev] = {**processed[rev], **to_merge}
processed[rev] = processed[rev] | to_merge
if "workspace" in processed:
del processed["workspace"]
+5 -5
View File
@@ -181,7 +181,7 @@ SCHEMA = {
"remote": {
str: ByUrl(
{
"": {**LOCAL_COMMON, **REMOTE_COMMON},
"": LOCAL_COMMON | REMOTE_COMMON,
"s3": {
"region": str,
"profile": str,
@@ -285,10 +285,10 @@ SCHEMA = {
Optional("verify", default=True): Bool,
**REMOTE_COMMON,
},
"http": {**HTTP_COMMON, **REMOTE_COMMON},
"https": {**HTTP_COMMON, **REMOTE_COMMON},
"webdav": {**WEBDAV_COMMON, **REMOTE_COMMON},
"webdavs": {**WEBDAV_COMMON, **REMOTE_COMMON},
"http": HTTP_COMMON | REMOTE_COMMON,
"https": HTTP_COMMON | REMOTE_COMMON,
"webdav": WEBDAV_COMMON | REMOTE_COMMON,
"webdavs": WEBDAV_COMMON | REMOTE_COMMON,
"remote": {str: object}, # Any of the above options are valid
}
)
+1 -1
View File
@@ -158,5 +158,5 @@ def get_cloud_fs(repo_config, **kwargs):
fs_path = cls._strip_protocol(url)
extras = cls._get_kwargs_from_urls(url)
conf = {**extras, **remote_conf} # remote config takes priority
conf = extras | remote_conf # remote config takes priority
return cls, conf, fs_path
+1 -1
View File
@@ -1478,7 +1478,7 @@ META_SCHEMA = {
Meta.PARAM_VERSION_ID: str,
}
CLOUD_SCHEMA = vol.All({str: {**META_SCHEMA, **CHECKSUMS_SCHEMA}}, vol.Length(max=1))
CLOUD_SCHEMA = vol.All({str: META_SCHEMA | CHECKSUMS_SCHEMA}, vol.Length(max=1))
ARTIFACT_SCHEMA: dict[Any, Any] = {
**CHECKSUMS_SCHEMA,
+1 -1
View File
@@ -68,7 +68,7 @@ class Tqdm(tqdm):
"""
kwargs = kwargs.copy()
if bytes:
kwargs = {**self.BYTES_DEFAULTS, **kwargs}
kwargs = self.BYTES_DEFAULTS | kwargs
else:
kwargs.setdefault("unit_scale", total > 999 if total else True)
if file is None:
+2 -2
View File
@@ -285,7 +285,7 @@ class VegaConverter(Converter):
if not all_datapoints:
return [], {}
properties = {**properties, **props_update}
properties = properties | props_update
return all_datapoints, properties
@@ -298,7 +298,7 @@ class VegaConverter(Converter):
inferred_properties = self._infer_x_y()
datapoints = self._find_datapoints()
properties = {**self.properties, **inferred_properties}
properties = self.properties | inferred_properties
properties["y_label"] = self.infer_y_label(properties)
properties["x_label"] = self.infer_x_label(properties)
+1 -1
View File
@@ -25,7 +25,7 @@ def _squash_plots_properties(data: list) -> dict:
configs = [last(group) for group in data]
resolved: dict = {}
for config in reversed(configs):
resolved = {**resolved, **config}
resolved = resolved | config
return resolved
+1 -1
View File
@@ -614,7 +614,7 @@ class BaseExecutor(ABC):
# set missing config options using saved config
# inferring repo url will fail if not set here
run_env_config = env_to_config(kwargs.get("run_env", {}))
dvc_studio_config = {**run_env_config, **dvc_studio_config}
dvc_studio_config = run_env_config | dvc_studio_config
try:
post_live_metrics(
"start",
+1 -1
View File
@@ -337,7 +337,7 @@ class BaseStashQueue(ABC):
studio_config = get_studio_config(
dvc_studio_config=self.repo.config.get("studio")
)
run_env = {**config_to_env(studio_config), **run_env}
run_env = config_to_env(studio_config) | run_env
self._pack_args(*args, run_env=run_env, **kwargs)
# save experiment as a stash commit
msg = self._stash_msg(
+1 -1
View File
@@ -77,7 +77,7 @@ def tabulate(
"State",
"Executor",
]
names = {**metrics_names, **params_names}
names = metrics_names | params_names
counter = Counter(flatten_list([list(a.keys()) for a in names.values()]))
counter.update(headers)
metrics_headers = _normalize_headers(metrics_names, counter)
+4 -4
View File
@@ -171,7 +171,7 @@ class Plots:
plots = _collect_plots(repo, targets, recursive)
res: dict[str, Any] = {}
for fs_path, rev_props in plots.items():
joined_props = {**rev_props, **props}
joined_props = rev_props | props
res[fs_path] = {"props": joined_props}
res[fs_path].update(
{
@@ -405,7 +405,7 @@ def _collect_output_plots(repo, targets, props, onerror: Optional[Callable] = No
unpacked = unpack_if_dir(
fs,
_normpath(fs.join(wdir_relpath, plot.def_path)),
props={**plot_props, **props},
props=plot_props | props,
onerror=onerror,
)
@@ -449,12 +449,12 @@ def _resolve_definitions(
data_path = _normpath(fs.join(config_dir, plot_id))
if _matches(targets, config_path, plot_id):
unpacked = unpack_if_dir(
fs, data_path, props={**plot_props, **props}, onerror=onerror
fs, data_path, props=plot_props | props, onerror=onerror
)
dpath.merge(result, unpacked)
elif _matches(targets, config_path, plot_id):
adjusted_props = _adjust_sources(fs, plot_props, config_dir)
dpath.merge(result, {"data": {plot_id: {**adjusted_props, **props}}})
dpath.merge(result, {"data": {plot_id: adjusted_props | props}})
return result
+1 -1
View File
@@ -71,7 +71,7 @@ PLOT_PROPS = {
Output.PARAM_PLOT_TITLE: str,
Output.PARAM_PLOT_HEADER: bool,
}
PLOT_PROPS_SCHEMA = {**OUT_PSTAGE_DETAILED_SCHEMA[str], **PLOT_PROPS}
PLOT_PROPS_SCHEMA = OUT_PSTAGE_DETAILED_SCHEMA[str] | PLOT_PROPS
PLOT_PSTAGE_SCHEMA = {str: vol.Any(PLOT_PROPS_SCHEMA, [PLOT_PROPS_SCHEMA])}
PARAM_PSTAGE_NON_DEFAULT_SCHEMA = {str: [str]}
+1 -1
View File
@@ -6,7 +6,7 @@ if TYPE_CHECKING:
def issubset(subset: dict, superset: dict) -> bool:
assert superset == {**superset, **subset}
assert superset == superset | subset
return True