> Is the intent of using int and friends as constructors instead of just > coercion functions that I should (eventually) be able to do this: > > class NonNegativeInt(int): > def __init__(self, val): > if int(val) < 0: > raise ValueError, "Value must be >= 0" > int.__init__(self, val) > self.a = 47 > ... > > ? Yes, sort-of. The details will be slightly different. I'm not comfortable with letting a user-provided __init__() method change the value of self, so I am brooding on a work-around that separates allocation and one-time initialization from __init__(). Watch PEP 253. --Guido van Rossum (home page: http://www.python.org/~guido/)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4