Python will raise an appropriate error if it's not an integer, so there is no need to put your own over the top of it.
Let's step back a bit though, as there are other problems here. getters and setters are really unpythonic - either just use an attribute, or use properties.
In this case, I think you are still thinking in the wrong way. The reason we don't type check in Python is because we shouldn't care what type something is, just if it will work in the given situation. Making everything the type you think it should be as soon as you get it is essentially type checking.
You say it will make it harder to debug, but that's not really the experience most people have. Duck typing is designed to allow anything that can do the job do the job. Converting everything to an int
limits your program. The problem isn't here, the problem is with your code that is passing something that doesn't make sense to your class. In my experience, this is actually a really rare thing to do - you don't tend to throw random stuff at classes and see what sticks.
So, my suggestion here is that you use an attribute - just do x.age = ...
instead of using set_age()
or anything like that. If you really need to have an int
(as in, only whole numbers make sense), then use a property and call int()
in the setter, leaving the error to propagate to the caller if it happens.