Skip to content

Commit

Permalink
Exclude 'None' values from type check
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Hupfeldt Nielsen committed May 22, 2012
1 parent dd844d3 commit 10c5b46
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
12 changes: 7 additions & 5 deletions multiconf.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,20 @@ def __call__(self, **kwargs):

defaults = self._container._defaults
if self._attribute_name in defaults:
attr_types.add(type(defaults[self._attribute_name]))
if defaults[self._attribute_name] != None:
attr_types.add(type(defaults[self._attribute_name]))

# Validate and assign given env values to container
for eg_name, value in kwargs.iteritems():
try:
eg = env_or_group(eg_name)

# Validate that an attribute has the same type for all envs
if type(value) not in attr_types and attr_types:
msg = "Found different types of property " + repr(self._attribute_name) + " for different envs: " + repr(type(value)) + " previously found types: " + repr(list(attr_types))
errors = _error_msg(errors, msg)
attr_types.add(type(value))
if type(value) != type(None):
if type(value) not in attr_types and attr_types:
msg = "Found different types of property " + repr(self._attribute_name) + " for different envs: " + repr(type(value)) + " previously found types: " + repr(list(attr_types))
errors = _error_msg(errors, msg)
attr_types.add(type(value))

# TODO: allow env overrides group, allow group nested override?
for env in eg.envs():
Expand Down
6 changes: 6 additions & 0 deletions test/multiconf_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,3 +102,9 @@ def _e(self):
key, value = actual
ok (exp_key) == key
ok (exp_value) == value

@test("property defined with same type and None")
def _g(self):
with ConfigRoot(prod, [prod, pp], a=None) as cr:
cr.a(prod=1, pp=2)
ok (cr.a) == 1

0 comments on commit 10c5b46

Please sign in to comment.