mirror of
https://github.com/mikf/gallery-dl.git
synced 2024-11-25 20:22:36 +01:00
[util] extend CustomNone with comparison operators
This commit is contained in:
parent
1ce5de0290
commit
7614bc458e
@ -106,12 +106,12 @@ def identity(x):
|
|||||||
return x
|
return x
|
||||||
|
|
||||||
|
|
||||||
def true(_):
|
def true(_, __=None):
|
||||||
"""Always returns True"""
|
"""Always returns True"""
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
def false(_):
|
def false(_, __=None):
|
||||||
"""Always returns False"""
|
"""Always returns False"""
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -540,10 +540,21 @@ class CustomNone():
|
|||||||
def __bool__():
|
def __bool__():
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
__lt__ = true
|
||||||
|
__le__ = true
|
||||||
|
__eq__ = false
|
||||||
|
__ne__ = true
|
||||||
|
__gt__ = false
|
||||||
|
__ge__ = false
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __len__():
|
def __len__():
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def __hash__():
|
||||||
|
return 0
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __format__(_):
|
def __format__(_):
|
||||||
return "None"
|
return "None"
|
||||||
|
@ -745,6 +745,7 @@ def hash(value):
|
|||||||
self.assertEqual(repr(obj), repr(None))
|
self.assertEqual(repr(obj), repr(None))
|
||||||
self.assertEqual(format(obj), str(None))
|
self.assertEqual(format(obj), str(None))
|
||||||
self.assertEqual(format(obj, "%F"), str(None))
|
self.assertEqual(format(obj, "%F"), str(None))
|
||||||
|
|
||||||
self.assertIs(obj.attr, obj)
|
self.assertIs(obj.attr, obj)
|
||||||
self.assertIs(obj["key"], obj)
|
self.assertIs(obj["key"], obj)
|
||||||
self.assertIs(obj(), obj)
|
self.assertIs(obj(), obj)
|
||||||
@ -752,6 +753,17 @@ def hash(value):
|
|||||||
self.assertIs(obj(foo="bar"), obj)
|
self.assertIs(obj(foo="bar"), obj)
|
||||||
self.assertEqual(util.json_dumps(obj), "null")
|
self.assertEqual(util.json_dumps(obj), "null")
|
||||||
|
|
||||||
|
self.assertLess(obj, "foo")
|
||||||
|
self.assertLessEqual(obj, None)
|
||||||
|
self.assertFalse(obj == obj)
|
||||||
|
self.assertTrue(obj != obj)
|
||||||
|
self.assertGreater(123, obj)
|
||||||
|
self.assertGreaterEqual(1.23, obj)
|
||||||
|
|
||||||
|
mapping = {}
|
||||||
|
mapping[obj] = 123
|
||||||
|
self.assertIn(obj, mapping)
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
for _ in obj:
|
for _ in obj:
|
||||||
i += 1
|
i += 1
|
||||||
|
Loading…
Reference in New Issue
Block a user