-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deprecation warnings #38
Changes from 1 commit
1f2f105
4d3d01d
0ad2949
e0984b1
b7a39e7
255fe5f
530180d
0eb7c21
f40323a
5b3d77b
7a2e3d4
bad4ff4
3b2504d
1b71cc3
dcbf330
356426c
f9543d5
14a77fa
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,7 +46,7 @@ class BooleanIndex(UnIndex): | |
has a roughly equal 50/50 split. | ||
""" | ||
|
||
meta_type = "BooleanIndex" | ||
meta_type = 'BooleanIndex' | ||
|
||
manage_options = ( | ||
{'label': 'Settings', | ||
|
@@ -55,7 +55,7 @@ class BooleanIndex(UnIndex): | |
'action': 'manage_browse'}, | ||
) | ||
|
||
query_options = ["query"] | ||
query_options = ['query'] | ||
|
||
manage = manage_main = DTMLFile('dtml/manageBooleanIndex', globals()) | ||
manage_main._setName('manage_main') | ||
|
@@ -137,8 +137,8 @@ def removeForwardIndexEntry(self, entry, documentId, check=True): | |
raise | ||
except Exception: | ||
LOG.exception( | ||
'%s: unindex_object could not remove documentId %s ' | ||
'from index %s. This should not happen.' % ( | ||
'{0}: unindex_object could not remove documentId {1} ' | ||
'from index {2}. This should not happen.'.format( | ||
self.__class__.__name__, | ||
str(documentId), | ||
str(self.id))) | ||
|
@@ -174,8 +174,8 @@ def _index_object(self, documentId, obj, threshold=None, attr=''): | |
raise | ||
except Exception: | ||
LOG.error('Should not happen: oldDatum was there, now ' | ||
'its not, for document with id %s' % | ||
documentId) | ||
'its not, for document with id {0}'.format( | ||
documentId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
if datum is not _marker: | ||
self.insertForwardIndexEntry(datum, documentId) | ||
|
@@ -203,7 +203,7 @@ def unindex_object(self, documentId): | |
raise | ||
except Exception: | ||
LOG.debug('Attempt to unindex nonexistent document' | ||
' with id %s' % documentId, exc_info=True) | ||
' with id {0}'.format(documentId), exc_info=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, too. |
||
|
||
def query_index(self, record, resultset=None): | ||
index = self._index | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,8 +142,8 @@ def rawAttributes(self): | |
return self._attributes | ||
|
||
def __repr__(self): | ||
return "<id: %s; metatype: %s; attributes: %s>" % \ | ||
(self.id, self.meta_type, self.attributes) | ||
return '<id: {0}; metatype: {1}; attributes: {2}>'.format( | ||
self.id, self.meta_type, self.attributes) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To my mind it would be easier to read if written like this: |
||
|
||
|
||
@implementer(ITransposeQuery) | ||
|
@@ -153,7 +153,7 @@ class CompositeIndex(KeywordIndex): | |
or sequences of items | ||
""" | ||
|
||
meta_type = "CompositeIndex" | ||
meta_type = 'CompositeIndex' | ||
|
||
manage_options = ( | ||
{'label': 'Settings', | ||
|
@@ -162,7 +162,7 @@ class CompositeIndex(KeywordIndex): | |
'action': 'manage_browse'}, | ||
) | ||
|
||
query_options = ("query", "operator") | ||
query_options = ('query', 'operator') | ||
|
||
def __init__(self, id, ignore_ex=None, call_methods=None, | ||
extra=None, caller=None): | ||
|
@@ -304,8 +304,8 @@ def make_query(self, query): | |
zc = aq_parent(aq_parent(self)) | ||
skip = zc.getProperty('skip_compositeindex', False) | ||
if skip: | ||
LOG.debug('%s: skip composite query build %r' % | ||
(self.__class__.__name__, zc)) | ||
LOG.debug('{0}: skip composite query build {1}'.format( | ||
self.__class__.__name__, repr(zc))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, too. |
||
return query | ||
except AttributeError: | ||
pass | ||
|
@@ -377,7 +377,7 @@ def addComponent(self, c_id, c_meta_type, c_attributes): | |
# Add a component object by 'c_id'. | ||
if c_id in self._components: | ||
raise KeyError('A component with this ' | ||
'name already exists: %s' % c_id) | ||
'name already exists: {0}'.format(c_id)) | ||
|
||
self._components[c_id] = Component(c_id, | ||
c_meta_type, | ||
|
@@ -387,7 +387,7 @@ def addComponent(self, c_id, c_meta_type, c_attributes): | |
def delComponent(self, c_id): | ||
# Delete the component object specified by 'c_id'. | ||
if c_id not in self._components: | ||
raise KeyError('no such Component: %s' % c_id) | ||
raise KeyError('no such Component: {0}'.format(c_id)) | ||
|
||
del self._components[c_id] | ||
|
||
|
@@ -488,8 +488,8 @@ def manage_fastBuild(self, threshold=None, URL1=None, | |
if RESPONSE: | ||
RESPONSE.redirect(URL1 + '/manage_main?' | ||
'manage_tabs_message=ComponentIndex%%20fast%%20' | ||
'reindexed%%20in%%20%.3f%%20' | ||
'seconds%%20(%.3f%%20cpu)' % (tt, ct)) | ||
'reindexed%%20in%%20{0:.3f}%%20' | ||
'seconds%%20({1:.3f}%%20cpu)'.format(tt, ct)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe the query string should be constructed using |
||
|
||
manage = manage_main = DTMLFile('dtml/manageCompositeIndex', globals()) | ||
manage_main._setName('manage_main') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,9 +142,9 @@ def index_object(self, documentId, obj, threshold=None): | |
except ConflictError: | ||
raise | ||
except Exception: | ||
LOG.error("Should not happen: ConvertedDate was there," | ||
" now it's not, for document with id %s" % | ||
documentId) | ||
LOG.error('Should not happen: ConvertedDate was there,' | ||
' now it\'s not, for document' | ||
' with id {0}'.format(documentId)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
|
||
if ConvertedDate is not _marker: | ||
self.insertForwardIndexEntry(ConvertedDate, documentId) | ||
|
@@ -186,15 +186,16 @@ def _convert(self, value, default=None): | |
|
||
# flatten to precision | ||
if self.precision > 1: | ||
t_val = t_val - (t_val % self.precision) | ||
t_val = t_val - (t_val % self.precision) # noqa: S001 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I personally think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can hope that this false positive will be solved, s. gforcada/flake8-pep3101#23. Otherwise, wait and see. |
||
|
||
t_val = int(t_val) | ||
|
||
if t_val > MAX32: | ||
# t_val must be integer fitting in the 32bit range | ||
raise OverflowError( | ||
"%s is not within the range of indexable dates (index: %s)" | ||
% (value, self.id)) | ||
('{0} is not within the range of' | ||
' indexable dates (index: {1})'.format( | ||
value, self.id))) | ||
return t_val | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ | |
# | ||
############################################################################## | ||
|
||
import sys | ||
from logging import getLogger | ||
|
||
from BTrees.OOBTree import difference | ||
|
@@ -37,7 +36,7 @@ class KeywordIndex(UnIndex): | |
|
||
This should have an _apply_index that returns a relevance score | ||
""" | ||
meta_type = "KeywordIndex" | ||
meta_type = 'KeywordIndex' | ||
query_options = ('query', 'range', 'not', 'operator') | ||
|
||
manage_options = ( | ||
|
@@ -135,9 +134,9 @@ def unindex_object(self, documentId): | |
try: | ||
del self._unindex[documentId] | ||
except KeyError: | ||
LOG.debug('%s: Attempt to unindex nonexistent ' | ||
'document with id %s' % | ||
(self.__class__.__name__, documentId), | ||
LOG.debug('{0}: Attempt to unindex nonexistent ' | ||
'document with id {1}'.format( | ||
self.__class__.__name__, documentId), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here. |
||
exc_info=True) | ||
|
||
manage = manage_main = DTMLFile('dtml/manageKeywordIndex', globals()) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -55,7 +55,7 @@ class PathIndex(Persistent, SimpleItem): | |
'all docids with this path component on this level' | ||
""" | ||
|
||
meta_type = "PathIndex" | ||
meta_type = 'PathIndex' | ||
|
||
operators = ('or', 'and') | ||
useOperator = 'or' | ||
|
@@ -134,8 +134,10 @@ def unindex_object(self, docid): | |
""" See IPluggableIndex. | ||
""" | ||
if docid not in self._unindex: | ||
LOG.debug('Attempt to unindex nonexistent document with id %s' | ||
% docid) | ||
LOG.debug('Attempt to unindex nonexistent ' | ||
'document with id {0}'.format( | ||
docid)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, too. |
||
|
||
return | ||
|
||
comps = self._unindex[docid].split('/') | ||
|
@@ -150,8 +152,9 @@ def unindex_object(self, docid): | |
if not self._index[comp]: | ||
del self._index[comp] | ||
except KeyError: | ||
LOG.debug('Attempt to unindex document with id %s failed' | ||
% docid) | ||
LOG.debug('Attempt to unindex document ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, too. |
||
'with id {0} failed'.format( | ||
docid)) | ||
|
||
self._length.change(-1) | ||
del self._unindex[docid] | ||
|
@@ -277,8 +280,8 @@ def _search(self, path, default_level=0): | |
if level < 0: | ||
# Search at every level, return the union of all results | ||
return multiunion( | ||
[self._search(path, level) | ||
for level in range(self._depth + 1)]) | ||
[self._search(path, lvl) | ||
for lvl in range(self._depth + 1)]) | ||
|
||
comps = list(filter(None, path.split('/'))) | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -65,7 +65,10 @@ def setExpression(self, expr): | |
self.expr = expr | ||
|
||
def __repr__(self): | ||
return '%s: (%s) %s' % (self.id, self.expr, list(map(None, self.ids))) | ||
return '{0}: ({1}) {2}'.format( | ||
self.id, self.expr, | ||
list(map(None, self.ids)) | ||
) | ||
|
||
__str__ = __repr__ | ||
|
||
|
@@ -86,13 +89,13 @@ def index_object(self, documentId, o): | |
except ConflictError: | ||
raise | ||
except Exception: | ||
LOG.warn('eval() failed Object: %s, expr: %s' % | ||
(o.getId(), self.expr), exc_info=sys.exc_info()) | ||
LOG.warn('eval() failed Object: {0}, expr: {1}'.format( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, too. |
||
o.getId(), self.expr), exc_info=sys.exc_info()) | ||
|
||
|
||
def factory(f_id, f_type, expr): | ||
""" factory function for FilteredSets """ | ||
if f_type == 'PythonFilteredSet': | ||
return PythonFilteredSet(f_id, expr) | ||
else: | ||
raise TypeError('unknown type for FilteredSets: %s' % f_type) | ||
raise TypeError('unknown type for FilteredSets: {0}'.format(f_type)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although on other places it is beneficial to change to the
.format()
version, for logging it might be better to add the parameter as*args
to theLOG.exception()
as it gets formatted later on anyway. But as the initial case did not used this way, I can live with that here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd really like to see using the logging parameters in the intended way: https://docs.python.org/3/howto/logging.html#logging-variable-data Logging does not (yet?) support format. The reason behind the
%
notation in the format string and the added values using commas is a performance one: The logging text is only rendered when it is actually logged. To me it seems to be easier to use the%
syntax everywhere for logging instead of reasoning about the performance impact at every logging statement.