You can get the class from int in python, for example. class MyInt(int) , but this type in python is immutable (you cannot change the value) after creating it.
You could do something like this:
class MyInt: def __init__(self, i, max=None, min=None): self.max = max self.min = min self.set(i) def set(self, i): if i > self.max: raise ValueError if i < self.min: raise ValueError self.i = i def toInt(self): return self.i def __getattr__(self, name):
Itβs better to use the usual validation functions depending on what you want, but if it's easier.
EDIT : working now - reverting to a simpler earlier version, having add functions, etc. that return other instances of MyInt, is simply not worth it :-)
source share