Skip to content

Commit

Permalink
linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
jamadden committed Jun 27, 2023
1 parent 7442ad9 commit bbabb1d
Show file tree
Hide file tree
Showing 122 changed files with 585 additions and 395 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,12 @@ jobs:
with:
name: RelStorage-${{ runner.os }}-${{ matrix.python-version }}.whl
path: dist/*whl
# XXX: Temp comment out linting until tests run again.
# - name: lint
# if: matrix.python-version == '3.11' && startsWith(runner.os, 'Linux')
# # At this writing, PyLint 2.17/astroid 2.15 won't work on 3.12
# run: |
# pip install -U pylint
# python -m pylint --limit-inference-results=1 --rcfile=.pylintrc relstorage -f parseable -r n
- name: lint
if: matrix.python-version == '3.11' && startsWith(runner.os, 'Linux')
# At this writing, PyLint 2.17/astroid 2.15 won't work on 3.12
run: |
pip install -U pylint
python -m pylint --limit-inference-results=1 --rcfile=.pylintrc relstorage -f parseable -r n
- name: Initialize Test Databases
if: startsWith(runner.os, 'macOS')
run: |
Expand Down
8 changes: 7 additions & 1 deletion .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ init-hook =
# readable, thing
# unnecessary-lambda-assignment: We use this pattern a fair amount
# redefined-variable-type: Fairly common

# compare-to-zero: Often makes things less readable; an explicit == 0 can be better than 'not foo'
disable=wrong-import-position,
wrong-import-order,
missing-docstring,
Expand All @@ -140,6 +140,9 @@ disable=wrong-import-position,
unnecessary-lambda-assignment,
redefined-variable-type,
cyclic-import,
compare-to-zero,
missing-param-doc,
missing-type-doc,

enable=consider-using-augmented-assign

Expand Down Expand Up @@ -195,9 +198,12 @@ max-complexity=11
# pylint leaves it off. This is the proximal cause of the
# undefined-all-variable crash.
unsafe-load-any-extension = yes
extension-pkg-allow-list = relstorage.cache._objectindex,relstorage.cache.cache,relstorage._inthashmap
# This does not seem to work, hence the init-hook
property-classes=zope.cachedescriptors.property.Lazy,zope.cachedescriptors.property.Cached



[CLASSES]
# List of interface methods to ignore, separated by a comma. This is used for
# instance to not check methods defines in Zope's Interface base class.
Expand Down
6 changes: 3 additions & 3 deletions src/relstorage/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ def byte_display(size):
"""
Returns a string with the correct unit (KB, MB), given the size in bytes.
"""
if size == 0:
if not size:
return '0 KB'
if size <= 1024:
return '%s bytes' % size
Expand Down Expand Up @@ -531,7 +531,7 @@ def __getattr__(self, name):
def __setattr__(self, name, value):
if name in CloseTracker.__slots__:
object.__setattr__(self, name, value)
return
return None
return setattr(self._tracked, name, value)

def close(self):
Expand Down Expand Up @@ -573,7 +573,7 @@ class NeedsFetchallBeforeCloseCursor(CloseTrackerCursor): # pragma: no cover
def close(self):
if self.needs_fetchall:
raise AssertionError("Forgot to fetchall")
super(NeedsFetchallBeforeCloseCursor, self).close()
super().close()

def execute(self, stmt, args=None):
if self.needs_fetchall:
Expand Down
2 changes: 1 addition & 1 deletion src/relstorage/adapters/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def prop(inst):
raise query

if extension:
query = query + extension
query += extension
if formatted:
query = intern(query % inst.runner.script_vars)

Expand Down
1 change: 1 addition & 0 deletions src/relstorage/adapters/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def lock_objects_and_detect_conflicts(self, cursor, read_current_oids):
self._describe_best_lock_objects_and_detect_conflicts(),
kind
)
return None # unreachable

def _composed_lock_objects_and_detect_conflicts(self, cursor, read_current_oids):
read_current_oid_ints = read_current_oids.keys()
Expand Down
3 changes: 2 additions & 1 deletion src/relstorage/adapters/connmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def _connection_callback_open_args(connmanager, callback):
read_only = getattr(callback, 'transaction_read_only', None)
deferrable = getattr(callback, 'transaction_deferrable', None)
application_name = getattr(callback, 'transaction_application_name', None)
return dict(
return dict( # pylint:disable=use-dict-literal
isolation=isolation or connmanager.isolation_store,
read_only=read_only or False,
deferrable=deferrable or False,
Expand All @@ -73,6 +73,7 @@ class AbstractConnectionManager(object):
Responsible for opening and closing database connections.
"""
# pylint:disable=too-many-instance-attributes

# a series of callables (cursor, restart=bool)
# for when a store connection is opened.
Expand Down
18 changes: 9 additions & 9 deletions src/relstorage/adapters/drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def __init__(self):
"or the driver was set to 'auto', there may be more drivers to attempt.",
self.__name__, self.MODULE_NAME,
exc_info=True)
raise DriverNotImportableError(self.__name__, reason=str(ex))
raise DriverNotImportableError(self.__name__, reason=str(ex)) from ex


self.disconnected_exceptions = (mod.OperationalError,
Expand Down Expand Up @@ -196,12 +196,12 @@ def _sockets_gevent_monkey_patched(self):
from gevent import monkey
except ImportError: # pragma: no cover
return False
else:
# some versions of gevent have a bug where if we're monkey-patched
# on the command line using python -m gevent.monkey /path/to/testrunner ...
# it doesn't report being monkey-patched.
import socket
return monkey.is_module_patched('socket') or 'gevent' in repr(socket.socket)

# some versions of gevent have a bug where if we're monkey-patched
# on the command line using python -m gevent.monkey /path/to/testrunner ...
# it doesn't report being monkey-patched.
import socket
return monkey.is_module_patched('socket') or 'gevent' in repr(socket.socket)

# Common compatibility shims, overriden as needed.

Expand Down Expand Up @@ -404,7 +404,7 @@ class _NoGeventConnectionMixin(object):
gevent_write_watcher = None
gevent_sleep = None

try:
try: # pylint:disable=too-complex
import gevent
except ImportError:
GeventDriverMixin = _NoGeventDriverMixin
Expand Down Expand Up @@ -488,7 +488,7 @@ class GeventConnectionMixin(_NoGeventConnectionMixin):

def close(self):
self.__close_watchers()
super(GeventConnectionMixin, self).close()
super().close()

def __check_watchers(self):
# We can be used from more than one thread in a sequential
Expand Down
33 changes: 14 additions & 19 deletions src/relstorage/adapters/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,34 +59,34 @@ class IDBDriver(Interface):
__name__ = Attribute("The name of this driver")

disconnected_exceptions = Tuple(
description=(u"A tuple of exceptions this driver can raise on any operation if it is "
u"disconnected from the database."),
description=("A tuple of exceptions this driver can raise on any operation if it is "
"disconnected from the database."),
value_type=Factory(IException)
)

close_exceptions = Tuple(
description=(u"A tuple of exceptions that we can ignore when we try to "
u"close the connection to the database. Often this is the same "
u"or an extension of `disconnected_exceptions`."
u"These exceptions may also be ignored on rolling back the connection, "
u"if we are otherwise completely done with it and prepared to drop it. "),
description=("A tuple of exceptions that we can ignore when we try to "
"close the connection to the database. Often this is the same "
"or an extension of `disconnected_exceptions`."
"These exceptions may also be ignored on rolling back the connection, "
"if we are otherwise completely done with it and prepared to drop it. "),
value_type=Factory(IException),
)

lock_exceptions = Tuple(
description=u"A tuple of exceptions",
description="A tuple of exceptions",
value_type=Factory(IException),
) # XXX: Document

use_replica_exceptions = Tuple(
description=(u"A tuple of exceptions raised by connecting "
u"that should cause us to try a replica."),
description=("A tuple of exceptions raised by connecting "
"that should cause us to try a replica."),
value_type=Factory(IException)
)

Binary = Attribute("A callable.")

dialect = Object(IDBDialect, description=u"The IDBDialect for this driver.")
dialect = Object(IDBDialect, description="The IDBDialect for this driver.")

cursor_arraysize = Attribute(
"The value to assign to each new cursor's ``arraysize`` attribute.")
Expand Down Expand Up @@ -252,7 +252,7 @@ class DriverNotAvailableError(Exception):
reason = None

def __init__(self, driver_name, driver_options=None, reason=None):
super(DriverNotAvailableError, self).__init__(driver_name)
super().__init__(driver_name)
self.driver_name = driver_name
self.driver_options = driver_options
self.reason = reason
Expand Down Expand Up @@ -304,7 +304,7 @@ class NoDriversAvailableError(DriverNotAvailableError):
"""

def __init__(self, driver_name='auto', driver_options=None, reason=None):
super(NoDriversAvailableError, self).__init__(driver_name, driver_options, reason)
super().__init__(driver_name, driver_options, reason)


class IDBDriverOptions(Interface):
Expand Down Expand Up @@ -574,11 +574,6 @@ def __bool__():
Return true if the database connection is believed to be ready to use.
"""

def __nonzero__():
"""
Same as __bool__ for Python 2.
"""

def drop():
"""
Unconditionally drop (close) the database connection.
Expand Down Expand Up @@ -1248,7 +1243,7 @@ class IRelStorageAdapter(Interface):
driver = Object(IDBDriver)
connmanager = Object(IConnectionManager)
dbiter = Object(IDatabaseIterator)
keep_history = Bool(description=u"True if this adapter supports undo")
keep_history = Bool(description="True if this adapter supports undo")
locker = Object(ILocker)
mover = Object(IObjectMover)
oidallocator = Object(IOIDAllocator)
Expand Down
30 changes: 14 additions & 16 deletions src/relstorage/adapters/mover.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,7 @@ def get_object_tid_after(self, cursor, oid, tid):
"""
self._get_tid_after_query.execute(cursor, (oid, tid))
row = cursor.fetchone()
if row:
return row[0]
return row[0] if row else None

_current_object_tids_queries = (
(('zoid', 'tid'), 'current_object', 'zoid'),
Expand Down Expand Up @@ -354,20 +353,19 @@ def _generic_restore(self, batcher, oid, tid, data,
command=command,
suffix=suffix
)
else:
elif data:
# history free can only delete the entire record.
if data:
batcher.insert_into(
"object_state (zoid, tid, state_size, state)",
"%s, %s, %s, %s",
(oid, tid, size, encoded),
rowkey=oid,
size=size,
command=command,
suffix=suffix
)
else:
batcher.delete_from('object_state', zoid=oid)
batcher.insert_into(
"object_state (zoid, tid, state_size, state)",
"%s, %s, %s, %s",
(oid, tid, size, encoded),
rowkey=oid,
size=size,
command=command,
suffix=suffix
)
else:
batcher.delete_from('object_state', zoid=oid)

def restore(self, cursor, batcher, oid, tid, data):
raise NotImplementedError()
Expand Down Expand Up @@ -574,7 +572,7 @@ def download_blob(self, cursor, oid, tid, filename):
break

if f is None:
f = open(filename, 'wb')
f = open(filename, 'wb') # pylint:disable=consider-using-with

f.write(chunk)
bytecount += len(chunk)
Expand Down
6 changes: 3 additions & 3 deletions src/relstorage/adapters/mysql/adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def __init__(self, options=None, oidallocator=None,
self.connmanager = connmanager
self.locker = locker
self.mover = mover
super(MySQLAdapter, self).__init__(options)
super().__init__(options)

def _create(self):
options = self.options
Expand Down Expand Up @@ -233,7 +233,7 @@ def lock_database_and_choose_next_tid(self,
args = ()
if self.keep_history:
# (packed, username, descr, extension)
proc = proc + '(%s, %s, %s, %s)'
proc += '(%s, %s, %s, %s)'
args = (False, username, description, extension)

multi_results = self.driver.callproc_multi_result(cursor, proc, args)
Expand All @@ -252,7 +252,7 @@ def lock_database_and_move(self,
if not self.version_detector.supports_good_stored_procs(store_connection.cursor):
# XXX: When can we drop this? Probably not until AppVeyor upgrades
# MySQL past 5.7.12.
return super(MySQLAdapter, self).lock_database_and_move(
return super().lock_database_and_move(
store_connection, load_connection,
transaction_has_blobs,
ude,
Expand Down
2 changes: 1 addition & 1 deletion src/relstorage/adapters/mysql/connmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, driver, params, options):
self._params = params.copy()
self._db_connect = driver.connect
self._db_driver = driver
super(MySQLdbConnectionManager, self).__init__(options, driver)
super().__init__(options, driver)

self.isolation_load = self.isolation_repeatable_read_ro
self.isolation_store = self.isolation_read_committed
Expand Down
8 changes: 4 additions & 4 deletions src/relstorage/adapters/mysql/drivers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def can_prepare(self):
# If there are params, we can't prepare unless we're using
# the binary protocol; otherwise we have to SET user variables
# with extra round trips, which is worse.
return not self.placeholders and super(MySQLCompiler, self).can_prepare()
return not self.placeholders and super().can_prepare()

_PREPARED_CONJUNCTION = 'FROM'

Expand Down Expand Up @@ -142,7 +142,7 @@ class AbstractMySQLDriver(AbstractModuleDriver):
_init_command = ''

def __init__(self):
super(AbstractMySQLDriver, self).__init__()
super().__init__()

kv = ["%s=%s" % (k, v) for k, v in self.MY_SESSION_VARS.items()]
self._init_command = "SET " + ", ".join(kv)
Expand All @@ -156,13 +156,13 @@ def cursor(self, conn, server_side=False):
cursor = conn.cursor(self._server_side_cursor)
cursor.arraysize = self.cursor_arraysize
else:
cursor = super(AbstractMySQLDriver, self).cursor(conn, server_side=False)
cursor = super().cursor(conn, server_side=False)
return cursor

def connect(self, *args, **kwargs):
if self._init_command:
kwargs['init_command'] = self._init_command
return super(AbstractMySQLDriver, self).connect(*args, **kwargs)
return super().connect(*args, **kwargs)

def synchronize_cursor_for_rollback(self, cursor):
"""Does nothing."""
Expand Down
Loading

0 comments on commit bbabb1d

Please sign in to comment.