Don't need to implement __new__ to make an immutable class

This commit is contained in:
Daniele Varrazzo 2012-09-24 00:46:43 +01:00
parent a858987844
commit b1953640d2

View File

@ -55,8 +55,7 @@ class Range(object):
"""
__slots__ = ('_lower', '_upper', '_bounds')
def __new__(cls, lower=None, upper=None, bounds='[)', empty=False):
self = super(Range, cls).__new__(cls)
def __init__(self, lower=None, upper=None, bounds='[)', empty=False):
if not empty:
if bounds not in ('[)', '(]', '()', '[]'):
raise ValueError("bound flags not valid: %r" % bounds)
@ -67,8 +66,6 @@ class Range(object):
else:
self._lower = self._upper = self._bounds = None
return self
def __repr__(self):
if self._bounds is None:
return "%s(empty=True)" % self.__class__.__name__