Don't unnecessarily recast lists and dicts
authorJeremy Stanley <fungi@yuggoth.org>
Mon, 2 Jun 2014 06:31:26 +0000 (06:31 +0000)
committerJeremy Stanley <fungi@yuggoth.org>
Mon, 2 Jun 2014 06:31:26 +0000 (06:31 +0000)
* lib/mudpy/misc.py(Element.getlist,Element.getdict): Unlike INI, YAML
directly encodes other datatypes in addition to strings. When using get
functions for lists and dicts, if they're already provided in their
desired form then don't recast them as doing so would instead create
nested datatypes instead.

lib/mudpy/misc.py

index 84d1a5e..c6fd97d 100644 (file)
@@ -224,7 +224,10 @@ class Element:
             default = []
         value = self.get(facet)
         if value:
-            return mudpy.data.makelist(value)
+            if type(value) is list:
+                return value
+            else:
+                return mudpy.data.makelist(value)
         else:
             return default
 
@@ -234,7 +237,10 @@ class Element:
             default = {}
         value = self.get(facet)
         if value:
-            return mudpy.data.makedict(value)
+            if type(value) is dict:
+                return value
+            else:
+                return mudpy.data.makedict(value)
         else:
             return default