- summary: Typechecking should be interface checkin --> Typechecking should be interface checking
That is, instead of:
if type(inputList) != types.ListType:
raise SomeError, 'expecting list, got %s' \
% repr(inputList)
if not isinstance(inputObject, MyClass):
raise SomeError, 'expecting MyClass, got %s' \
% repr(inputObject)
inputList.append(42)
inputObject.fooMethod(42)
you should do:
try:
listAppend = inputList.append
except AttributeError:
raise SomeError, '%s has no append method' \
% repr(inputList)
try:
objectMethod = inputObject.fooMethod
except AttributeError:
raise SomeError, '%s has no fooMethod method' \
% repr(inputObject)
Should we be raising TypeError during these checks?
Should we use assert and raise AssertionError?
Assert would allow -o to be used when compiling
for optimization, which I _believe_ drops asserts.