[tor-commits] [stem/master] Use isinstance for type checks

atagar at torproject.org atagar at torproject.org
Sun Jan 6 22:56:20 UTC 2013


commit 1bb38dd2460c0674d97d88504763b2c63ba6e72b
Author: Sean Robinson <seankrobinson at gmail.com>
Date:   Fri Jan 4 15:32:34 2013 -0700

    Use isinstance for type checks
    
    Change the four uses of type() == x to the more Pythonic isinstance idiom.
    
    Signed-off-by: Sean Robinson <seankrobinson at gmail.com>
---
 stem/control.py             |    4 ++--
 stem/descriptor/__init__.py |    2 +-
 stem/util/conf.py           |    2 +-
 3 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/stem/control.py b/stem/control.py
index b22adfd..6dfb7f2 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1467,7 +1467,7 @@ class Controller(BaseController):
       * :class:`stem.InvalidArguments` if features passed were invalid
     """
     
-    if type(features) == str: features = [features]
+    if isinstance(features, str): features = [features]
     response = self.msg("USEFEATURE %s" % " ".join(features))
     stem.response.convert("SINGLELINE", response)
     
@@ -1609,7 +1609,7 @@ class Controller(BaseController):
           raise stem.InvalidRequest(512, "EXTENDCIRCUIT requires the path prior to version %s" % path_opt_version)
       
       args = [circuit_id]
-      if type(path) == str: path = [path]
+      if isinstance(path, str): path = [path]
       if path: args.append(",".join(path))
       if purpose: args.append("purpose=%s" % purpose)
       
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 3aaf5fd..c66f298 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -196,7 +196,7 @@ def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_fi
   content = None if skip else []
   ending_keyword = None
   
-  if type(keywords) == str: keywords = (keywords,)
+  if isinstance(keywords, str): keywords = (keywords,)
   
   if ignore_first:
     first_line = descriptor_file.readline()
diff --git a/stem/util/conf.py b/stem/util/conf.py
index e15313c..7f4cebe 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -586,7 +586,7 @@ class Config(object):
     :returns: given configuration value with its type inferred with the above rules
     """
     
-    is_multivalue = type(default) in (list, tuple, dict)
+    is_multivalue = isinstance(default, (list, tuple, dict))
     val = self.get_value(key, default, is_multivalue)
     if val == default: return val # don't try to infer undefined values
     





More information about the tor-commits mailing list