[util] extend CustomNone with an __index__ method (#6009)

- Make it compatible with functions expecting integer arguments
- Simplify and reuse some method definitions
This commit is contained in:
Mike Fährmann
2024-08-13 15:57:17 +02:00
parent ad73789256
commit 5208c0d28a
2 changed files with 17 additions and 15 deletions

View File

@@ -520,14 +520,9 @@ class CustomNone():
"""None-style type that supports more operations than regular None"""
__slots__ = ()
def __getattribute__(self, _):
return self
def __getitem__(self, _):
return self
def __iter__(self):
return self
__getattribute__ = identity
__getitem__ = identity
__iter__ = identity
def __call__(self, *args, **kwargs):
return self
@@ -536,10 +531,6 @@ class CustomNone():
def __next__():
raise StopIteration
@staticmethod
def __bool__():
return False
def __eq__(self, other):
return self is other
@@ -550,6 +541,7 @@ class CustomNone():
__le__ = true
__gt__ = false
__ge__ = false
__bool__ = false
__add__ = identity
__sub__ = identity
@@ -588,9 +580,8 @@ class CustomNone():
def __len__():
return 0
@staticmethod
def __hash__():
return 0
__hash__ = __len__
__index__ = __len__
@staticmethod
def __format__(_):