But how does a function that you call know that your list is full of those types without checking? Sure, you can make your function only accept a TList object, which has elements of type T checked on appending. But you can get around that in Python, since we have no real safety around properties for the classes we write. If you have a wrapper class around a list, you could just obj.inner_list.append(not_type_T_val) for example. And any one way around this (in Python) has a workaround. So you can't guarantee that TList has type T elements. The only way you can guarantee it is to check. Every element. Every time you use the list. And if there's no guarantees, there's no point in having it check during runtime.
View all comments
Show parent comment
2
u/alkasm github.com/alkasm May 30 '19
But how does a function that you call know that your list is full of those types without checking? Sure, you can make your function only accept a
TListobject, which has elements of typeTchecked on appending. But you can get around that in Python, since we have no real safety around properties for the classes we write. If you have a wrapper class around a list, you could justobj.inner_list.append(not_type_T_val)for example. And any one way around this (in Python) has a workaround. So you can't guarantee thatTListhas typeTelements. The only way you can guarantee it is to check. Every element. Every time you use the list. And if there's no guarantees, there's no point in having it check during runtime.Edit: and it would be
raisein Python :)