Skip to content

Commit

Permalink
ANY object is not singleton after unpickle
Browse files Browse the repository at this point in the history
  • Loading branch information
pohmelie committed Jan 26, 2018
1 parent 6d7762f commit da63abb
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions skin.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class SkinValueError(ValueError):


DEFAULT_VALUE = object()
ANY = object()
FORBIDDEN = (str, bytes, bytearray, memoryview, range)


Expand All @@ -32,17 +31,17 @@ def _special_method(name):

class Skin:

def __init__(self, value=DEFAULT_VALUE, *, allowed=ANY, forbidden=FORBIDDEN, _parent=None, _parent_name=None):
def __init__(self, value=DEFAULT_VALUE, *, allowed="ANY", forbidden=FORBIDDEN, _parent=None, _parent_name=None):
if value is DEFAULT_VALUE:
value = {}
if isinstance(value, self.__class__):
value = value.value
else:
if not hasattr(value, "__getitem__"):
raise SkinValueError("{!r} have no '__getitem__' method".format(value))
if allowed is not ANY and not isinstance(value, allowed):
if allowed != "ANY" and not isinstance(value, allowed):
raise SkinValueError("{!r} not in allowed".format(value))
if forbidden is ANY or isinstance(value, forbidden):
if forbidden == "ANY" or isinstance(value, forbidden):
raise SkinValueError("{!r} in forbidden".format(value))
setter = super().__setattr__
setter("value", value)
Expand Down

0 comments on commit da63abb

Please sign in to comment.