From 15cb807c2ff6c736bb0ef32967eda551190a20df Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Mon, 11 Mar 2019 14:35:49 +0100 Subject: [PATCH] Use isinstance() instead of type() is ~ --- PgDB.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/PgDB.py b/PgDB.py index efbef2a..6fcc570 100644 --- a/PgDB.py +++ b/PgDB.py @@ -75,25 +75,25 @@ class PgDB(object): # SQL helpers # def _quote_value(self, value): - if type(value) is int or type(value) is float: + if isinstance(value, int) or isinstance(value, float): return unicode(value) - if type(value) is str: + if isinstance(value, str): value = unicode(value) - elif type(value) is datetime.datetime: + elif isinstance(value, datetime.datetime): value = unicode(self._format_datetime(value)) - elif type(value) is datetime.date: + elif isinstance(value, datetime.date): value = unicode(self._format_date(value)) return u"'%s'" % value.replace(u"'",u"''") def _format_where_clauses(self, where_clauses, where_op=u'AND'): - if type(where_clauses) is str: + if isinstance(where_clauses, str): return where_clauses - elif type(where_clauses) is list: + elif isinstance(where_clauses, list): return (u" %s " % where_op).join(where_clauses) - elif type(where_clauses) is dict: - return (u" %s " % where_op).join(map(lambda x: "%s=%s" % (x, _quote_value(where_clauses[x])), where_clauses)) + elif isinstance(where_clauses, dict): + return (u" %s " % where_op).join(map(lambda x: "%s=%s" % (x, self._quote_value(where_clauses[x])), where_clauses)) logging.error('Unsupported where clauses type %s', type(where_clauses)) return False @@ -160,7 +160,7 @@ class PgDB(object): sql = u"SELECT " if fields is None: sql += "*" - elif type(fields) in (str, unicode): + elif isinstance(fields, str) or isinstance(fields, unicode): sql += fields else: sql += u", ".join(fields)