Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Prevent errors when removing nested options values (Config) #21454

Merged
merged 2 commits into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions spyder/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,17 +560,32 @@ def remove_option(self, section, option):
"""Remove `option` from `section`."""
config = self.get_active_conf(section)
if isinstance(option, tuple):
# The actual option saved in the config
base_option = option[0]

# Keys of the nested dicts where the option to remove is contained
dalthviz marked this conversation as resolved.
Show resolved Hide resolved
intermediate_options = option[1:-1]

# Key of the option to remove
dalthviz marked this conversation as resolved.
Show resolved Hide resolved
last_option = option[-1]

# Get config value (which is a dictionary)
base_conf = self.get(section, base_option)

# Get reference to the actual dictionary containing the option
dalthviz marked this conversation as resolved.
Show resolved Hide resolved
# that needs to be removed
conf_ptr = base_conf
for opt in intermediate_options:
conf_ptr = conf_ptr[opt]
conf_ptr.pop(last_option)
self.set(section, base_option)
self.notify_observers(section, base_option)

# Remove option and set updated config values for the actual option
dalthviz marked this conversation as resolved.
Show resolved Hide resolved
# while checking that the option to be removed is actually a value
# available in the config.
# See spyder-ide/spyder#21161
if last_option in conf_ptr:
conf_ptr.pop(last_option)
self.set(section, base_option, base_conf)
self.notify_observers(section, base_option)
else:
config.remove_option(section, option)

Expand Down