335: If Command.__convert_scalar() is called with None, it now returns None instead of raising TypeError

This commit is contained in:
Jason Gerard DeRose committed 2008-09-24 06:48:27 +00:00
1 parent 4215da30ad
commit e63c462f31
2 files changed
+11 -9

No files matched your search

+8 -3
View File
@@ -106,6 +106,8 @@ class Param(plugable.ReadOnly):
lock(self)
def __dispatch(self, value, scalar):
if value is None:
return None
if self.multivalue:
if type(value) in (tuple, list):
if len(value) == 0:
@@ -146,7 +148,7 @@ class Param(plugable.ReadOnly):
def __convert_scalar(self, value, index=None):
if value is None:
raise TypeError('value cannot be None')
return None
converted = self.type(value)
if converted is None:
raise errors.ConversionError(
@@ -155,10 +157,13 @@ class Param(plugable.ReadOnly):
return converted
def convert(self, value):
"""
Convert/coerce ``value`` to Python type for this parameter.
:param value: A proposed value for this parameter.
"""
return self.__dispatch(value, self.__convert_scalar)
def __validate_scalar(self, value, index=None):
if type(value) is not self.type.type:
raise_TypeError(value, self.type.type, 'value')
+3 -6
View File
@@ -148,8 +148,7 @@ class test_Param(ClassChecker):
# Scenario 1: multivalue=False
o = self.cls(name, type_)
e = raises(TypeError, o.convert, None)
assert str(e) == 'value cannot be None'
assert o.convert(None) is None
for value in okay:
new = o.convert(value)
assert new == 7
@@ -163,10 +162,8 @@ class test_Param(ClassChecker):
# Scenario 2: multivalue=True
o = self.cls(name, type_, multivalue=True)
assert o.convert([]) is None
for none in [None, (7, None)]:
e = raises(TypeError, o.convert, none)
assert str(e) == 'value cannot be None'
for none in (None, tuple(), []):
assert o.convert(none) is None
for value in okay:
assert o.convert((value,)) == (7,)
assert o.convert([value]) == (7,)