changeset 8661:1394d16cc82a

lib: remove now unused class Optional Last usage was removed in previous commit.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Fri, 09 Oct 2020 20:09:40 +0200
parents 9398244a2525
children ad5c3a18ee9f
files kallithea/lib/utils2.py kallithea/tests/api/api_base.py
diffstat 2 files changed, 0 insertions(+), 52 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/utils2.py	Fri Oct 09 20:07:46 2020 +0200
+++ b/kallithea/lib/utils2.py	Fri Oct 09 20:09:40 2020 +0200
@@ -466,48 +466,6 @@
         return None
 
 
-class Optional(object):
-    """
-    Defines an optional parameter::
-
-        param = param.getval() if isinstance(param, Optional) else param
-        param = param() if isinstance(param, Optional) else param
-
-    is equivalent of::
-
-        param = Optional.extract(param)
-
-    """
-
-    def __init__(self, type_):
-        self.type_ = type_
-
-    def __repr__(self):
-        return '<Optional:%s>' % self.type_.__repr__()
-
-    def __call__(self):
-        return self.getval()
-
-    def getval(self):
-        """
-        returns value from this Optional instance
-        """
-        return self.type_
-
-    @classmethod
-    def extract(cls, val):
-        """
-        Extracts value from Optional() instance
-
-        :param val:
-        :return: original value if it's not Optional instance else
-            value of instance
-        """
-        if isinstance(val, cls):
-            return val.getval()
-        return val
-
-
 def urlreadable(s, _cleanstringsub=re.compile('[^-a-zA-Z0-9./]+').sub):
     return _cleanstringsub('_', s).rstrip('_')
 
--- a/kallithea/tests/api/api_base.py	Fri Oct 09 20:07:46 2020 +0200
+++ b/kallithea/tests/api/api_base.py	Fri Oct 09 20:09:40 2020 +0200
@@ -135,16 +135,6 @@
         given = ext_json.loads(given)
         assert expected == given, (expected, given)
 
-    def test_Optional_object(self):
-        from kallithea.controllers.api.api import Optional
-
-        option1 = Optional(None)
-        assert '<Optional:%s>' % None == repr(option1)
-        assert option1() is None
-
-        assert 1 == Optional.extract(Optional(1))
-        assert 'trololo' == Optional.extract('trololo')
-
     def test_api_wrong_key(self):
         id_, params = _build_data('trololo', 'get_user')
         response = api_call(self, params)