mirror of
https://github.com/ynput/ayon-core.git
synced 2025-12-25 05:14:40 +01:00
CustomNone moved to pype's lib
This commit is contained in:
parent
d30cc41e8b
commit
9a167bec7f
2 changed files with 40 additions and 21 deletions
40
pype/lib.py
40
pype/lib.py
|
|
@ -572,3 +572,43 @@ def get_subsets(asset_name,
|
||||||
"representaions": repres_out}
|
"representaions": repres_out}
|
||||||
|
|
||||||
return output_dict
|
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))
|
||||||
|
|
|
||||||
|
|
@ -31,27 +31,6 @@ class RestMethods(enum.Enum):
|
||||||
return default
|
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):
|
class HandlerDict(dict):
|
||||||
def __init__(self, data=None, *args, **kwargs):
|
def __init__(self, data=None, *args, **kwargs):
|
||||||
if not data:
|
if not data:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue