From 971d88e71b6e82ea4da02272be05f20506f4bf1b Mon Sep 17 00:00:00 2001 From: Laurent Monin Date: Wed, 6 Sep 2023 23:54:12 +0200 Subject: [PATCH] Rename id to profile_id where applicable `profile_id` is explicit. `id()` is a built-in function, see https://docs.python.org/3.10/library/functions.html#id --- picard/config.py | 18 ++++++++--------- picard/ui/options/profiles.py | 38 +++++++++++++++++------------------ 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/picard/config.py b/picard/config.py index dfb66bd9a3..73fc61b47c 100644 --- a/picard/config.py +++ b/picard/config.py @@ -168,23 +168,23 @@ def _get_active_profile_ids(self): yield profile["id"] def _get_active_profile_settings(self): - for id in self._get_active_profile_ids(): - yield id, self._get_profile_settings(id) + for profile_id in self._get_active_profile_ids(): + yield profile_id, self._get_profile_settings(profile_id) - def _get_profile_settings(self, id): + def _get_profile_settings(self, profile_id): if self.settings_override is None: - profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][id] + profile_settings = self.__qt_config.profiles[self.SETTINGS_KEY][profile_id] else: - profile_settings = self.settings_override[id] + profile_settings = self.settings_override[profile_id] if profile_settings is None: - log.error("Unable to find settings for user profile '%s'", id) + log.error("Unable to find settings for user profile '%s'", profile_id) return {} return profile_settings def __getitem__(self, name): # Don't process settings that are not profile-specific if name in UserProfileGroups.ALL_SETTINGS: - for id, settings in self._get_active_profile_settings(): + for profile_id, settings in self._get_active_profile_settings(): if name in settings and settings[name] is not None: return settings[name] opt = Option.get(self.__name, name) @@ -195,9 +195,9 @@ def __getitem__(self, name): def __setitem__(self, name, value): # Don't process settings that are not profile-specific if name in UserProfileGroups.ALL_SETTINGS: - for id, settings in self._get_active_profile_settings(): + for profile_id, settings in self._get_active_profile_settings(): if name in settings: - self._save_profile_setting(id, name, value) + self._save_profile_setting(profile_id, name, value) return key = self.key(name) self.__qt_config.setValue(key, value) diff --git a/picard/ui/options/profiles.py b/picard/ui/options/profiles.py index ddd0ffd12e..914e40403b 100644 --- a/picard/ui/options/profiles.py +++ b/picard/ui/options/profiles.py @@ -157,9 +157,9 @@ def load(self): if last_selected_profile: self.ui.profile_list.setCurrentItem(last_selected_profile) last_selected_profile.setSelected(True) - id = last_selected_profile.profile_id - self.current_profile_id = id - settings = self.get_settings_for_profile(id) + profile_id = last_selected_profile.profile_id + self.current_profile_id = profile_id + settings = self.get_settings_for_profile(profile_id) self.make_setting_tree(settings=settings) self.update_config_overrides() self.loading = False @@ -179,21 +179,21 @@ def update_config_overrides(self, reset=False): config.setting.set_profiles_override(self._clean_and_get_all_profiles()) config.setting.set_settings_override(self.profile_settings) - def get_settings_for_profile(self, id): + def get_settings_for_profile(self, profile_id): """Get the settings for the specified profile ID. Automatically adds an empty settings dictionary if there is no settings dictionary found for the ID. Args: - id (str): ID of the profile + profile_id (str): ID of the profile Returns: dict: Profile settings """ # Add empty settings dictionary if no dictionary found for the profile. # This happens when a new profile is created. - if id not in self.profile_settings: - self.profile_settings[id] = {} - return self.profile_settings[id] + if profile_id not in self.profile_settings: + self.profile_settings[profile_id] = {} + return self.profile_settings[profile_id] def _all_profiles(self): """Get all profiles from the profiles list in order from top to bottom. @@ -219,7 +219,7 @@ def make_setting_tree(self, settings=None): if settings is None: return self.building_tree = True - for id, group in UserProfileGroups.SETTINGS_GROUPS.items(): + for group in UserProfileGroups.SETTINGS_GROUPS.values(): title = group["title"] group_settings = group["settings"] widget_item = QtWidgets.QTreeWidgetItem([title]) @@ -326,10 +326,10 @@ def profile_selected(self, update_settings=True): """ item = self.get_current_selected_item() if item: - id = item.profile_id - self.current_profile_id = id + profile_id = item.profile_id + self.current_profile_id = profile_id if update_settings: - settings = self.get_settings_for_profile(id) + settings = self.get_settings_for_profile(profile_id) self.make_setting_tree(settings=settings) else: self.current_profile_id = None @@ -421,12 +421,12 @@ def copy_profile(self): """Make a copy of the currently selected profile. """ item = self.get_current_selected_item() - id = str(uuid.uuid4()) + profile_id = str(uuid.uuid4()) settings = deepcopy(self.profile_settings[self.current_profile_id]) - self.profile_settings[id] = settings + self.profile_settings[profile_id] = settings base_title = "%s %s" % (get_base_title(item.name), gettext_constants(DEFAULT_COPY_TEXT)) name = self.ui.profile_list.unique_profile_name(base_title) - self.ui.profile_list.add_profile(name=name, profile_id=id) + self.ui.profile_list.add_profile(name=name, profile_id=profile_id) self.update_config_overrides() self.reload_all_page_settings() @@ -456,11 +456,11 @@ def _clean_and_get_all_profiles(self): all_profile_ids = set(x['id'] for x in all_profiles) keys = set(self.profile_settings.keys()) # Add any missing profile settings - for id in all_profile_ids.difference(keys): - self.profile_settings[id] = {} + for profile_id in all_profile_ids.difference(keys): + self.profile_settings[profile_id] = {} # Remove any "orphan" profile settings - for id in keys.difference(all_profile_ids): - del self.profile_settings[id] + for profile_id in keys.difference(all_profile_ids): + del self.profile_settings[profile_id] return all_profiles def save(self):