CustomNone moved to pype's lib

This commit is contained in:
iLLiCiTiT 2019-11-25 10:50:46 +01:00
parent d30cc41e8b
commit 9a167bec7f
2 changed files with 40 additions and 21 deletions

View file

@ -572,3 +572,43 @@ def get_subsets(asset_name,
"representaions": repres_out}
return output_dict
class CustomNone:
"""Created object can be used as custom None (not equal to None).
WARNING: Multiple created objects are not equal either.
Exmple:
>>> a = CustomNone()
>>> a == None
False
>>> b = CustomNone()
>>> a == b
False
>>> a == a
True
"""
def __init__(self):
"""Create uuid as identifier for custom None."""
import uuid
self.identifier = str(uuid.uuid4())
def __bool__(self):
"""Return False (like default None)."""
return False
def __eq__(self, other):
"""Equality is compared by identifier value."""
if type(other) == type(self):
if other.identifier == self.identifier:
return True
return False
def __str__(self):
"""Return value of identifier when converted to string."""
return self.identifier
def __repr__(self):
"""Representation of custom None."""
return "<CustomNone-{}>".format(str(self.identifier))

View file

@ -31,27 +31,6 @@ class RestMethods(enum.Enum):
return default
class CustomNone:
"""Created object can be used as custom None (not equal to None)"""
def __init__(self, name):
self._name = name
def __bool__(self):
return False
def __eq__(self, other):
if type(other) == type(self):
if other._name == self._name:
return True
return False
def __str__(self):
return self._name
def __repr__(self):
return self._name
class HandlerDict(dict):
def __init__(self, data=None, *args, **kwargs):
if not data: