230: Renamed allow_None kwarg to allow_none

This commit is contained in:
Jason Gerard DeRose 2008-09-02 17:44:07 +00:00
parent f2da06c5cf
commit bc08225dcd
3 changed files with 15 additions and 15 deletions

View File

@ -63,22 +63,22 @@ def raise_TypeError(value, type_, name):
raise e
def check_type(value, type_, name, allow_None=False):
def check_type(value, type_, name, allow_none=False):
assert type(name) is str, TYPE_FORMAT % ('name', str, name)
assert type(type_) is type, TYPE_FORMAT % ('type_', type, type_)
assert type(allow_None) is bool, TYPE_FORMAT % ('allow_None', bool, allow_None)
if value is None and allow_None:
assert type(allow_none) is bool, TYPE_FORMAT % ('allow_none', bool, allow_none)
if value is None and allow_none:
return
if type(value) is not type_:
raise_TypeError(value, type_, name)
return value
def check_isinstance(value, type_, name, allow_None=False):
def check_isinstance(value, type_, name, allow_none=False):
assert type(type_) is type, TYPE_FORMAT % ('type_', type, type_)
assert type(name) is str, TYPE_FORMAT % ('name', str, name)
assert type(allow_None) is bool, TYPE_FORMAT % ('allow_None', bool, allow_None)
if value is None and allow_None:
assert type(allow_none) is bool, TYPE_FORMAT % ('allow_none', bool, allow_none)
if value is None and allow_none:
return
if not isinstance(value, type_):
raise_TypeError(value, type_, name)

View File

@ -95,7 +95,7 @@ class Option2(plugable.ReadOnly):
self.multivalue = check_type(multivalue, bool, 'multivalue')
self.default = default
self.default_from = check_type(default_from,
DefaultFrom, 'default_from', allow_None=True)
DefaultFrom, 'default_from', allow_none=True)
self.__normalize = normalize
self.rules = (type_.validate,) + rules
lock(self)

View File

@ -74,7 +74,7 @@ def test_check_type():
# Should pass:
assert value is f(value, type_, name)
assert None is f(None, type_, name, allow_None=True)
assert None is f(None, type_, name, allow_none=True)
# Should raise TypeError
check_TypeError(f, None, type_, name)
@ -91,10 +91,10 @@ def test_check_type():
e = raises(AssertionError, f, value, fail_type, name)
assert str(e) == type_format % ('type_', type, fail_type)
# allow_None not a bool:
# allow_none not a bool:
fail_bool = 0
e = raises(AssertionError, f, value, type_, name, allow_None=fail_bool)
assert str(e) == type_format % ('allow_None', bool, fail_bool)
e = raises(AssertionError, f, value, type_, name, allow_none=fail_bool)
assert str(e) == type_format % ('allow_none', bool, fail_bool)
def test_check_isinstance():
@ -109,7 +109,7 @@ def test_check_isinstance():
# Should pass:
assert value is f(value, type_, name)
assert value is f(value, basestring, name)
assert None is f(None, type_, name, allow_None=True)
assert None is f(None, type_, name, allow_none=True)
# Should raise TypeError
check_TypeError(f, None, type_, name)
@ -125,7 +125,7 @@ def test_check_isinstance():
e = raises(AssertionError, f, value, fail_type, name)
assert str(e) == type_format % ('type_', type, fail_type)
# allow_None not a bool:
# allow_none not a bool:
fail_bool = 0
e = raises(AssertionError, f, value, type_, name, allow_None=fail_bool)
assert str(e) == type_format % ('allow_None', bool, fail_bool)
e = raises(AssertionError, f, value, type_, name, allow_none=fail_bool)
assert str(e) == type_format % ('allow_none', bool, fail_bool)