Selaa lähdekoodia

change in how choice types selection is handled with the get method

Dimitri Korsch 4 vuotta sitten
vanhempi
commit
f87ead58ad
1 muutettua tiedostoa jossa 8 lisäystä ja 6 poistoa
  1. 8 6
      cvargparse/utils/enumerations.py

+ 8 - 6
cvargparse/utils/enumerations.py

@@ -34,13 +34,15 @@ class BaseChoiceType(Enum, metaclass=MetaBaseType):
 		return {e.name.lower(): e for e in cls}
 
 	@classmethod
-	def get(cls, key):
-		if isinstance(key, str):
-			return cls[key] if key in cls else cls.Default
-		elif isinstance(key, cls):
+	def get(cls, key=None):
+
+		if isinstance(key, str) and key in cls:
+			return cls[key]
+
+		if isinstance(key, cls):
 			return key
-		else:
-			raise ValueError("Unknown optimizer type: \"{}\"".format(key.__class__.__name__))
+
+		return cls.Default
 
 	@classmethod
 	def as_arg(cls, name, short_name=None, default=None, help_text=None, **kwargs):