Skip to content

Commit

Permalink
Flake8 the code.
Browse files Browse the repository at this point in the history
After fixing isort it got visible that we did not do this, yet.
  • Loading branch information
icemac committed Mar 28, 2024
1 parent 579d28f commit 510895a
Show file tree
Hide file tree
Showing 23 changed files with 422 additions and 301 deletions.
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def _read_file(filename):
},
python_requires='>=3.7',
install_requires=[
'zope.deferredimport',
'zope.interface',
"cffi ; platform_python_implementation == 'CPython'",
],
Expand Down
9 changes: 5 additions & 4 deletions src/persistent/_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _c_optimizations_available():
'persistent.picklecache': cPickleCache,
'persistent.timestamp': _timestamp,
}
except catch: # pragma: no cover (only Jython doesn't build extensions)
except catch: # pragma: no cover (only Jython doesn't build extensions)
return {}


Expand Down Expand Up @@ -93,7 +93,7 @@ def _should_attempt_c_optimizations():
"""
if _c_optimizations_required():
return True
if PYPY: # pragma: no cover
if PYPY: # pragma: no cover
return False
return not _c_optimizations_ignored()

Expand Down Expand Up @@ -157,7 +157,8 @@ def find_impl():
return py_impl

c_opts = _c_optimizations_available()
if not c_opts: # pragma: no cover (only Jython doesn't build extensions)
# only Jython doesn't build extensions:
if not c_opts: # pragma: no cover
return py_impl

__traceback_info__ = c_opts
Expand Down Expand Up @@ -189,7 +190,7 @@ def find_impl():
v = types.FunctionType(
v.__code__,
new_globals,
k, # name
k, # name
v.__defaults__,
v.__closure__,
)
Expand Down
2 changes: 1 addition & 1 deletion src/persistent/_ring_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#define cffi_ring_add(ring, elt) ring_add((CPersistentRing*)ring, (CPersistentRing*)elt)
#define cffi_ring_del(elt) ring_del((CPersistentRing*)elt)
#define cffi_ring_move_to_head(ring, elt) ring_move_to_head((CPersistentRing*)ring, (CPersistentRing*)elt)
"""
""" # noqa: E501 line too long

ffi.set_source('persistent._ring',
source,
Expand Down
11 changes: 9 additions & 2 deletions src/persistent/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
from zope.deferredimport import deprecated

# persistent.dict is deprecated. Use persistent.mapping
from persistent.mapping import PersistentMapping as PersistentDict

deprecated(
"`persistent.dict.PersistentDict` is deprecated. Use"
" `persistent.mapping.PersistentMapping` instead."
" This backward compatibility shim will be removed in persistent"
" version 6.",
PersistentDict='persistent.mapping:PersistentMapping',
)
21 changes: 11 additions & 10 deletions src/persistent/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

OID_TYPE = SERIAL_TYPE = bytes


class IPersistent(Interface):
"""Python persistent interface
Expand Down Expand Up @@ -356,6 +357,7 @@ def _p_delattr(name):

# TODO: document conflict resolution.


class IPersistentDataManager(Interface):
"""Provide services for managing persistent state.
Expand Down Expand Up @@ -399,13 +401,13 @@ def register(object):
"""

# Maybe later:
## def mtime(object):
## """Return the modification time of the object.
# def mtime(object):
# """Return the modification time of the object.

## The modification time may not be known, in which case None
## is returned. If non-None, the return value is the kind of
## timestamp supplied by Python's time.time().
## """
# The modification time may not be known, in which case None
# is returned. If non-None, the return value is the kind of
# timestamp supplied by Python's time.time().
# """


class IPickleCache(Interface):
Expand Down Expand Up @@ -510,7 +512,6 @@ def new_ghost(oid, obj):
If 'oid' is already in the cache, raise.
"""


def invalidate(to_invalidate):
""" Invalidate the indicated objects.
Expand All @@ -537,10 +538,10 @@ def update_object_size_estimation(oid, new_size):

cache_size = Attribute('Target size of the cache')
cache_drain_resistance = Attribute('Factor for draining cache below '
'target size')
'target size')
cache_non_ghost_count = Attribute('Number of non-ghosts in the cache '
'(XXX how is it different from '
'ringlen?')
'(XXX how is it different from '
'ringlen?')
cache_data = Attribute("Property: copy of our 'data' dict")
cache_klass_count = Attribute("Property: len of 'persistent_classes'")

Expand Down
9 changes: 5 additions & 4 deletions src/persistent/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ class PersistentList(UserList, persistent.Persistent):
as changed and automatically persisted.
.. versionchanged:: 4.5.2
Using the `clear` method, or deleting a slice (e.g., ``del inst[:]`` or ``del inst[x:x]``)
now only results in marking the instance as changed if it actually removed
items.
Using the `clear` method, or deleting a slice (e.g., ``del inst[:]`` or
``del inst[x:x]``) now only results in marking the instance as changed
if it actually removed items.
"""
__super_getitem = UserList.__getitem__
__super_setitem = UserList.__setitem__
Expand Down Expand Up @@ -67,7 +67,8 @@ def __getitem__(self, item):

if sys.version_info[:3] < (3, 7, 4): # pragma: no cover
# Likewise for __copy__.
# See https://github.com/python/cpython/commit/3645d29a1dc2102fdb0f5f0c0129ff2295bcd768
# See
# https://github.com/python/cpython/commit/3645d29a1dc2102fdb0f5f0c0129ff2295bcd768
def __copy__(self):
inst = self.__class__.__new__(self.__class__)
inst.__dict__.update(self.__dict__)
Expand Down
12 changes: 6 additions & 6 deletions src/persistent/mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ class PersistentMapping(IterableUserDict, persistent.Persistent):
__super_pop = IterableUserDict.pop
__super_popitem = IterableUserDict.popitem


# Be sure to make a deep copy of our ``data`` (See PersistentList.)
# See https://github.com/python/cpython/commit/3645d29a1dc2102fdb0f5f0c0129ff2295bcd768
# Be sure to make a deep copy of our ``data`` (See PersistentList.) See
# https://github.com/python/cpython/commit/3645d29a1dc2102fdb0f5f0c0129ff2295bcd768
# This was fixed in CPython 3.7.4, but we can't rely on that because it
# doesn't handle our old ``_container`` appropriately (it goes directly
# to ``self.__dict__``, bypassing the descriptor). The code here was initially
# doesn't handle our old ``_container`` appropriately (it goes directly to
# ``self.__dict__``, bypassing the descriptor). The code here was initially
# based on the version found in 3.7.4.

def __copy__(self):
inst = self.__class__.__new__(self.__class__)
inst.__dict__.update(self.__dict__)
Expand Down Expand Up @@ -141,7 +141,7 @@ def popitem(self):
# ``data`` when we have ``_container`` instead

@default
def data(self): # pylint:disable=method-hidden
def data(self): # pylint:disable=method-hidden
# We don't want to cause a write on read, so we're careful not to
# do anything that would cause us to become marked as changed, however,
# if we're modified, then the saved record will have data, not
Expand Down
Loading

0 comments on commit 510895a

Please sign in to comment.