Skip to content

Commit

Permalink
Fix problems the new flake8 version found.
Browse files Browse the repository at this point in the history
  • Loading branch information
icemac committed Jun 17, 2024
1 parent f9065f4 commit e963e80
Showing 1 changed file with 39 additions and 29 deletions.
68 changes: 39 additions & 29 deletions src/DocumentTemplate/DT_InSV.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

import roman


try:
import Missing
mv = Missing.Value
Expand All @@ -31,7 +30,10 @@ class sequence_variables:

alt_prefix = None

def __init__(self, items=None, query_string='', start_name_re=None,
def __init__(self,
items=None,
query_string='',
start_name_re=None,
alt_prefix=''):
if items is not None:
# Turn iterable into a list, to support key lookup
Expand Down Expand Up @@ -129,16 +131,18 @@ def query(self, *ignored):
if mo is not None:
v = mo.group(0)
l_ = mo.start(0)
query_string = (query_string[:l_] + # NOQA: W504
query_string[l_ + len(v) - 1:])
query_string = (
query_string[:l_] + # NOQA: W504
query_string[l_ + len(v) - 1:])

else:
l_ = reg.search_group(query_string, (0,))
l_ = reg.search_group(query_string, (0, ))
if l_:
v = l_[1]
l_ = l_[0]
query_string = (query_string[:l_] + # NOQA: W504
query_string[l_ + len(v) - 1:])
query_string = (
query_string[:l_] + # NOQA: W504
query_string[l_ + len(v) - 1:])

query_string = '?' + query_string[1:]
else:
Expand All @@ -148,8 +152,16 @@ def query(self, *ignored):
return query_string

statistic_names = (
'total', 'count', 'min', 'max', 'median', 'mean', 'variance',
'variance-n', 'standard-deviation', 'standard-deviation-n',
'total',
'count',
'min',
'max',
'median',
'mean',
'variance',
'variance-n',
'standard-deviation',
'standard-deviation-n',
)

def statistics(self, name, key):
Expand Down Expand Up @@ -245,13 +257,13 @@ def statistics(self, name, key):
else:
half = count // 2
try:
data['median-%s' % name] = (
values[half] + values[half - 1]) // 2
data['median-%s' %
name] = (values[half] + values[half - 1]) // 2
except Exception:
try:
data['median-%s' % name] = (
"between {} and {}".format(values[half],
values[half - 1]))
data['median-%s' %
name] = ("between {} and {}".format(
values[half], values[half - 1]))
except Exception:
pass

Expand All @@ -275,10 +287,9 @@ def next_batches(self, suffix='batches', key=''):
pass
r = []
while end < l_:
start, end, spam = opt(end + 1 - overlap, 0,
sz, orphan, sequence)
v = sequence_variables(self.items,
self.query_string, self.start_name_re)
start, end, spam = opt(end + 1 - overlap, 0, sz, orphan, sequence)
v = sequence_variables(self.items, self.query_string,
self.start_name_re)
d = v.data
d['batch-start-index'] = start - 1
d['batch-end-index'] = end - 1
Expand All @@ -305,10 +316,10 @@ def previous_batches(self, suffix='batches', key=''):
pass
r = []
while start > 1:
start, end, spam = opt(0, start - 1 + overlap,
sz, orphan, sequence)
v = sequence_variables(self.items,
self.query_string, self.start_name_re)
start, end, spam = opt(0, start - 1 + overlap, sz, orphan,
sequence)
v = sequence_variables(self.items, self.query_string,
self.start_name_re)
d = v.data
d['batch-start-index'] = start - 1
d['batch-end-index'] = end - 1
Expand All @@ -324,10 +335,9 @@ def previous_batches(self, suffix='batches', key=''):
'last': last,
'previous': previous_batches,
'next': next_batches,
# These two are for backward compatability with a missfeature:
'sequence-index': \
lambda self, suffix, key: self['sequence-' + suffix],
'sequence-index-is': \
# These two are for backward compatibility with a misfeature:
'sequence-index': lambda self, suffix, key: self['sequence-' + suffix],
'sequence-index-is':
lambda self, suffix, key: self['sequence-' + suffix],
}
for n in statistic_names:
Expand All @@ -340,10 +350,10 @@ def __setitem__(self, key, value):
key = key[9:]
self.data[self.alt_prefix + key] = value

def __getitem__(self, key,
def __getitem__(self,
key,
special_prefixes=special_prefixes,
special_prefix=special_prefixes.__contains__
):
special_prefix=special_prefixes.__contains__):
data = self.data
if key in data:
return data[key]
Expand Down

0 comments on commit e963e80

Please sign in to comment.