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