From 8dc162d8d0456418fe3949fdc7bf79ae9bb7fd78 Mon Sep 17 00:00:00 2001 From: Jon Dufresne Date: Tue, 12 Mar 2019 19:46:23 -0700 Subject: [PATCH] Use True/False instead of 1/0 to represent bool values Slightly more modern, readable, and Pythonic. --- lib/extras.py | 23 +++++++++++------------ setup.py | 10 +++++----- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/lib/extras.py b/lib/extras.py index 0ae2582e..d8ac7a73 100644 --- a/lib/extras.py +++ b/lib/extras.py @@ -73,8 +73,8 @@ class DictCursorBase(_cursor): raise NotImplementedError( "DictCursorBase can't be instantiated without a row factory.") super(DictCursorBase, self).__init__(*args, **kwargs) - self._query_executed = 0 - self._prefetch = 0 + self._query_executed = False + self._prefetch = False self.row_factory = row_factory def fetchone(self): @@ -135,23 +135,23 @@ class DictCursor(DictCursorBase): def __init__(self, *args, **kwargs): kwargs['row_factory'] = DictRow super(DictCursor, self).__init__(*args, **kwargs) - self._prefetch = 1 + self._prefetch = True def execute(self, query, vars=None): self.index = OrderedDict() - self._query_executed = 1 + self._query_executed = True return super(DictCursor, self).execute(query, vars) def callproc(self, procname, vars=None): self.index = OrderedDict() - self._query_executed = 1 + self._query_executed = True return super(DictCursor, self).callproc(procname, vars) def _build_index(self): - if self._query_executed == 1 and self.description: + if self._query_executed and self.description: for i in range(len(self.description)): self.index[self.description[i][0]] = i - self._query_executed = 0 + self._query_executed = False class DictRow(list): @@ -237,22 +237,21 @@ class RealDictCursor(DictCursorBase): def __init__(self, *args, **kwargs): kwargs['row_factory'] = RealDictRow super(RealDictCursor, self).__init__(*args, **kwargs) - self._prefetch = 0 def execute(self, query, vars=None): self.column_mapping = [] - self._query_executed = 1 + self._query_executed = True return super(RealDictCursor, self).execute(query, vars) def callproc(self, procname, vars=None): self.column_mapping = [] - self._query_executed = 1 + self._query_executed = True return super(RealDictCursor, self).callproc(procname, vars) def _build_index(self): - if self._query_executed == 1 and self.description: + if self._query_executed and self.description: self.column_mapping = [d[0] for d in self.description] - self._query_executed = 0 + self._query_executed = False class RealDictRow(dict): diff --git a/setup.py b/setup.py index 190ca633..555f0b00 100644 --- a/setup.py +++ b/setup.py @@ -528,7 +528,7 @@ parser.read('setup.cfg') # Choose a datetime module have_pydatetime = True have_mxdatetime = False -use_pydatetime = int(parser.get('build_ext', 'use_pydatetime')) +use_pydatetime = parser.getboolean('build_ext', 'use_pydatetime') # check for mx package mxincludedir = '' @@ -576,14 +576,14 @@ else: define_macros.append(('PSYCOPG_VERSION', PSYCOPG_VERSION_EX)) if parser.has_option('build_ext', 'have_ssl'): - have_ssl = int(parser.get('build_ext', 'have_ssl')) + have_ssl = parser.getboolean('build_ext', 'have_ssl') else: - have_ssl = 0 + have_ssl = False if parser.has_option('build_ext', 'static_libpq'): - static_libpq = int(parser.get('build_ext', 'static_libpq')) + static_libpq = parser.getboolean('build_ext', 'static_libpq') else: - static_libpq = 0 + static_libpq = False # And now... explicitly add the defines from the .cfg files. # Looks like setuptools or some other cog doesn't add them to the command line