Added TypeError exception to Name.create method

This commit is contained in:
Wyllys Ingersoll 2014-09-12 12:55:18 -04:00
parent ceaff6d7ac
commit e67f56ae56
1 changed files with 14 additions and 2 deletions

View File

@ -108,13 +108,25 @@ class Name(Struct):
value = name_value
elif isinstance(name_value, str):
value = cls.NameValue(name_value)
# else: the __validate function will throw TypeError
else:
name = self.__class__.__name__
msg = ErrorStrings.BAD_EXP_RECV
member = 'name_value'
raise TypeError(msg.format('{}.{}'.format(name, member),
'name_value', type(Name.NameValue),
type(self.name_value)))
if isinstance(name_type, Name.NameType):
n_type = name_type
elif isinstance(name_type, Enum):
n_type = cls.NameType(name_type)
# else: the __validate function will throw TypeError
else:
name = self.__class__.__name__
msg = ErrorStrings.BAD_EXP_RECV
member = 'name_type'
raise TypeError(msg.format('{}.{}'.format(name, member),
'name_type', type(Name.NameType),
type(self.name_type)))
return Name(name_value=value,
name_type=n_type)