I am trying to implement a Vector3 class in python. If I would write the Vector3 class in c++ or c# i would have X, Y, and Z members stored as floats but in python I read that ducktyping is the way to go. So according to my c++/c# knowledge I wrote something like this:
class Vector3:
def __init__(self, x=0.0, y=0.0, z=0.0):
assert (isinstance(x, float) or isinstance(x, int)) and (isinstance(y, float) or isinstance(y, int)) and \
(isinstance(z, float) or isinstance(z, int))
self.x = float(x)
self.y = float(y)
self.z = float(z)
The question is regarding the assert statements: Would you use them or not in this instance (a Vector3 implementation for math). I also used it for the operations like
def __add__(self, other):
assert isinstance(other, Vector3)
return Vector3(self.x + other.x, self.y + other.y, self.z + other.z)
Would you use assert in these instances or not? According to this website : https://wiki.python.org/moin/UsingAssertionsEffectively it should not be overused but for me as someone who used static typing all along, not checking for the same datatype is extremely weird.