]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
options: Remove dead code, test and lint updates 2412/head
authorBen Darnell <ben@bendarnell.com>
Sun, 3 Jun 2018 18:24:02 +0000 (14:24 -0400)
committerBen Darnell <ben@bendarnell.com>
Sun, 3 Jun 2018 18:24:02 +0000 (14:24 -0400)
tornado/options.py
tornado/test/options_test.py
tornado/test/options_test_types_str.cfg

index ba4c86b44111328095522dd47e41b6d1a121d4bb..a269d44eba140169822332d6e3b4d4a2741c580c 100644 (file)
@@ -367,8 +367,9 @@ class OptionParser(object):
             if normalized in self._options:
                 option = self._options[normalized]
                 if option.multiple:
-                    if not isinstance(config[name], list):
-                        raise Error("Option %r is required to be a list of %s" %
+                    if not isinstance(config[name], (list, str)):
+                        raise Error("Option %r is required to be a list of %s "
+                                    "or a comma-separated string" %
                                     (option.name, option.type.__name__))
 
                 if type(config[name]) == str and option.type != str:
@@ -376,7 +377,6 @@ class OptionParser(object):
                 else:
                     option.set(config[name])
 
-
         if final:
             self.run_parse_callbacks()
 
@@ -500,19 +500,16 @@ class _Option(object):
             basestring_type: self._parse_string,
         }.get(self.type, self.type)
         if self.multiple:
-            if isinstance(value, list):
-                self._value = value
-            else:
-                self._value = []
-                for part in value.split(","):
-                    if issubclass(self.type, numbers.Integral):
-                        # allow ranges of the form X:Y (inclusive at both ends)
-                        lo, _, hi = part.partition(":")
-                        lo = _parse(lo)
-                        hi = _parse(hi) if hi else lo
-                        self._value.extend(range(lo, hi + 1))
-                    else:
-                        self._value.append(_parse(part))
+            self._value = []
+            for part in value.split(","):
+                if issubclass(self.type, numbers.Integral):
+                    # allow ranges of the form X:Y (inclusive at both ends)
+                    lo, _, hi = part.partition(":")
+                    lo = _parse(lo)
+                    hi = _parse(hi) if hi else lo
+                    self._value.extend(range(lo, hi + 1))
+                else:
+                    self._value.append(_parse(part))
         else:
             self._value = _parse(value)
         if self.callback is not None:
index 6ada3c26dc3f5ad6098c2709192aa3709382a4b2..9db64be30430ce544d8f27d69ca019682bfdc597 100644 (file)
@@ -25,14 +25,14 @@ except ImportError:
 
 
 class Email(object):
-   def __init__(self, value):
+    def __init__(self, value):
         if isinstance(value, str) and '@' in value:
             self._value = value
         else:
             raise ValueError()
 
-   @property
-   def value(self):
+    @property
+    def value(self):
         return self._value
 
 
index f02873a4307332624983c743c98ddfad5c449d27..25dfbc2bf514b32ac4a03800fbac6988511021c8 100644 (file)
@@ -5,4 +5,4 @@ float = 1.5
 datetime = '2013-04-28 05:16'
 timedelta = '45s'
 email = 'tornado@web.com'
-list_of_int = [1, 2, 3]
+list_of_int = '1,2,3'