Skip to content
Snippets Groups Projects
Commit 3b85355d authored by Pavel Kácha's avatar Pavel Kácha
Browse files

Fixed regression on unknown keys

parent 08f602f9
Branches
No related tags found
No related merge requests found
...@@ -42,7 +42,8 @@ person_init_data = { ...@@ -42,7 +42,8 @@ person_init_data = {
"address": { "address": {
"street": "Vrchlikova", "street": "Vrchlikova",
"num": 12.3, "num": 12.3,
"city": "Kocourkov" "city": "Kocourkov",
"unknown": "blah"
}, },
"discard1": "junk", "discard1": "junk",
"discard2": "garbage", "discard2": "garbage",
...@@ -76,7 +77,8 @@ class TestTypedDict(unittest.TestCase): ...@@ -76,7 +77,8 @@ class TestTypedDict(unittest.TestCase):
"address": { "address": {
"street": "Vrchlikova", "street": "Vrchlikova",
"num": 12, "num": 12,
"city": "Kocourkov"}}) "city": "Kocourkov",
"unknown": "blah"}})
def testSetGetKnownOk(self): def testSetGetKnownOk(self):
self.person["address"]["city"] = "Brno" self.person["address"]["city"] = "Brno"
...@@ -126,7 +128,7 @@ class TestTypedDict(unittest.TestCase): ...@@ -126,7 +128,7 @@ class TestTypedDict(unittest.TestCase):
it = self.person.items() it = self.person.items()
res = sorted([v for v in it]) res = sorted([v for v in it])
self.assertEqual(res, [ self.assertEqual(res, [
("address", {"city": "Kocourkov", "street": "Vrchlikova", "num": 12}), ("address", {"city": "Kocourkov", "street": "Vrchlikova", "num": 12, "unknown": "blah"}),
("age", 34), ("age", 34),
("name", "_Default_Value_"), ("name", "_Default_Value_"),
("note", None) ("note", None)
...@@ -136,7 +138,7 @@ class TestTypedDict(unittest.TestCase): ...@@ -136,7 +138,7 @@ class TestTypedDict(unittest.TestCase):
class TestOpenTypedDict(TestTypedDict): class TestOpenTypedDict(TestTypedDict):
def setUp(self): def setUp(self):
open_address_dict = OpenTypedDict(typedef=address_typedef.copy()) open_address_dict = OpenTypedDict(typedef=address_typedef.copy(), allow_unknown=True)
open_person_typedef = person_typedef.copy() open_person_typedef = person_typedef.copy()
open_person_typedef["address"] = open_address_dict open_person_typedef["address"] = open_address_dict
......
...@@ -10,7 +10,7 @@ Defines TypedDict and TypedList, which enforce inserted types based on simple ...@@ -10,7 +10,7 @@ Defines TypedDict and TypedList, which enforce inserted types based on simple
type definition. type definition.
""" """
__version__ = '0.1.10' __version__ = '0.1.11'
__author__ = 'Pavel Kácha <pavel.kacha@cesnet.cz>' __author__ = 'Pavel Kácha <pavel.kacha@cesnet.cz>'
import collections import collections
...@@ -130,7 +130,7 @@ class TypedDictBase(collections.MutableMapping): ...@@ -130,7 +130,7 @@ class TypedDictBase(collections.MutableMapping):
If key is not defined and allow_unknown is True, empty If key is not defined and allow_unknown is True, empty
definition is returned, otherwise KeyNotAllowed gets raised. definition is returned, otherwise KeyNotAllowed gets raised.
""" """
tdef = {} tdef = {"type": Any}
try: try:
tdef = self.typedef[key] tdef = self.typedef[key]
except KeyError: except KeyError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment