Skip to content

Commit a91446c

Browse files
authored
Merge 6ef7a57 into d4c5c24
2 parents d4c5c24 + 6ef7a57 commit a91446c

1 file changed

Lines changed: 24 additions & 8 deletions

File tree

source/config/__init__.py

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@
3838
_transformSpec_AddFeatureFlagDefault,
3939
_validateConfig_featureFlag,
4040
)
41-
from typing import Any, Dict, List, Optional, Set
41+
from typing import (
42+
Any,
43+
Dict,
44+
List,
45+
Optional,
46+
Set,
47+
)
4248
import NVDAState
4349

4450

@@ -1056,6 +1062,7 @@ def __init__(self, validationFuncName):
10561062
# the default value, used when config is missing.
10571063
default = None # converted to the appropriate type
10581064

1065+
10591066
class AggregatedSection(object):
10601067
"""A view of a section of configuration which aggregates settings from all active profiles.
10611068
"""
@@ -1068,6 +1075,11 @@ def __init__(self, manager, path, spec, profiles):
10681075
self.profiles = profiles
10691076
self._cache = {}
10701077

1078+
@staticmethod
1079+
def _isSection(val: Any) -> bool:
1080+
"""Checks if a given value or spec is a section of a config profile."""
1081+
return isinstance(val, dict)
1082+
10711083
def __getitem__(self, key, checkValidity=True):
10721084
# Try the cache first.
10731085
try:
@@ -1082,7 +1094,7 @@ def __getitem__(self, key, checkValidity=True):
10821094

10831095
spec = self._spec.get(key)
10841096
foundSection = False
1085-
if isinstance(spec, dict):
1097+
if self._isSection(spec):
10861098
foundSection = True
10871099

10881100
# Walk through the profiles looking for the key.
@@ -1095,7 +1107,7 @@ def __getitem__(self, key, checkValidity=True):
10951107
# Indicate that this key doesn't exist in this profile.
10961108
subProfiles.append(None)
10971109
continue
1098-
if isinstance(val, dict):
1110+
if self._isSection(val):
10991111
foundSection = True
11001112
subProfiles.append(val)
11011113
else:
@@ -1208,11 +1220,10 @@ def dict(self):
12081220

12091221
def __setitem__(self, key, val):
12101222
spec = self._spec.get(key) if self.spec else None
1211-
if isinstance(spec, dict) and not isinstance(val, dict):
1223+
if self._isSection(spec) and not self._isSection(val):
12121224
raise ValueError("Value must be a section")
12131225

1214-
if isinstance(spec, dict) or isinstance(val, dict):
1215-
# The value is a section.
1226+
if self._isSection(spec) or self._isSection(val):
12161227
# Update the profile.
12171228
updateSect = self._getUpdateSection()
12181229
updateSect[key] = val
@@ -1243,8 +1254,13 @@ def __setitem__(self, key, val):
12431254
except KeyError:
12441255
pass
12451256
else:
1246-
if val == curVal:
1247-
# The value isn't different, so there's nothing to do.
1257+
if self._isSection(val) or self._isSection(curVal):
1258+
# If value is a section, continue to update
1259+
pass
1260+
elif str(val) == str(curVal):
1261+
# Check str comparison as this is what is written to the config.
1262+
# If the value is unchanged, do not update
1263+
# or mark the profile as dirty.
12481264
return
12491265

12501266
# Set this value in the most recently activated profile.

0 commit comments

Comments
 (0)