Browse Source

cfg.py: allow unsetting of previously set attrs

The MMGen Project 9 months ago
parent
commit
a8253a692b
1 changed files with 11 additions and 4 deletions
  1. 11 4
      mmgen/cfg.py

+ 11 - 4
mmgen/cfg.py

@@ -445,10 +445,17 @@ class Config(Lockable):
 			assert key.isascii() and key.isidentifier() and key[0] != '_', '{key!r}: malformed configuration option'
 			assert key.isascii() and key.isidentifier() and key[0] != '_', '{key!r}: malformed configuration option'
 			assert key not in self._forbidden_opts, '{key!r}: forbidden configuration option'
 			assert key not in self._forbidden_opts, '{key!r}: forbidden configuration option'
 			if key not in auto_opts:
 			if key not in auto_opts:
-				setattr(
-					self,
-					key,
-					conv_type(key, val, getattr(self,key), self._uopt_desc ) if hasattr(self,key) else val )
+				if hasattr(type(self), key):
+					setattr(
+						self,
+						key,
+						getattr(type(self), key) if val is None else
+							conv_type(key, val, getattr(type(self), key), self._uopt_desc))
+				elif val is None:
+					if hasattr(self, key):
+						delattr(self, key)
+				else:
+					setattr(self, key, val)
 
 
 		# Step 3: set cfg from environment, skipping already-set opts; save names set from environment:
 		# Step 3: set cfg from environment, skipping already-set opts; save names set from environment:
 		self._envopts = tuple(self._set_cfg_from_env()) if self._use_env else ()
 		self._envopts = tuple(self._set_cfg_from_env()) if self._use_env else ()