Skip to content

Commit

Permalink
Merge from 5.x: PR #21454
Browse files Browse the repository at this point in the history
Fixes #21161
  • Loading branch information
ccordoba12 committed Oct 25, 2023
2 parents 7f5edba + a7a31af commit 822f690
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions spyder/config/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,17 +561,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
intermediate_options = option[1:-1]

# Key of the option to remove
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
# 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
# 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

0 comments on commit 822f690

Please sign in to comment.