Skip to content

Commit

Permalink
Merge pull request #170 from SpiNNakerManchester/pylint_fix
Browse files Browse the repository at this point in the history
Pylint fix
  • Loading branch information
rowleya authored Mar 25, 2022
2 parents 647a2d6 + 237ff29 commit 496ce4e
Show file tree
Hide file tree
Showing 13 changed files with 24 additions and 107 deletions.
86 changes: 3 additions & 83 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -69,86 +69,7 @@ confidence=
# --enable=similarities". If you want to run only the classes checker, but have
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
disable=print-statement,
parameter-unpacking,
unpacking-in-except,
old-raise-syntax,
backtick,
long-suffix,
old-ne-operator,
old-octal-literal,
import-star-module-level,
non-ascii-bytes-literal,
raw-checker-failed,
bad-inline-option,
locally-disabled,
locally-enabled,
file-ignored,
suppressed-message,
useless-suppression,
deprecated-pragma,
apply-builtin,
basestring-builtin,
buffer-builtin,
cmp-builtin,
coerce-builtin,
execfile-builtin,
file-builtin,
long-builtin,
raw_input-builtin,
reduce-builtin,
standarderror-builtin,
unicode-builtin,
xrange-builtin,
coerce-method,
delslice-method,
getslice-method,
setslice-method,
no-absolute-import,
old-division,
dict-iter-method,
dict-view-method,
next-method-called,
metaclass-assignment,
indexing-exception,
raising-string,
reload-builtin,
oct-method,
hex-method,
nonzero-method,
cmp-method,
input-builtin,
round-builtin,
intern-builtin,
unichr-builtin,
map-builtin-not-iterating,
zip-builtin-not-iterating,
range-builtin-not-iterating,
filter-builtin-not-iterating,
using-cmp-argument,
eq-without-hash,
div-method,
idiv-method,
rdiv-method,
exception-message-attribute,
invalid-str-codec,
sys-max-int,
bad-python3-import,
deprecated-string-function,
deprecated-str-translate-call,
deprecated-itertools-function,
deprecated-types-field,
next-method-defined,
dict-items-not-iterating,
dict-keys-not-iterating,
dict-values-not-iterating,
invalid-name,
too-many-lines,
global-statement,
fixme,
protected-access,
attribute-defined-outside-init,
bad-option-value
disable=

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
Expand Down Expand Up @@ -342,15 +263,14 @@ single-line-if-stmt=no

# Logging modules to check that the string format arguments are in logging
# function parameter format
logging-modules=logging
logging-modules=logging,FormatAdapter


[MISCELLANEOUS]

# List of note tags to take in consideration, separated by a comma.
notes=FIXME,
XXX,
TODO
XXX


[SIMILARITIES]
Expand Down
1 change: 1 addition & 0 deletions spinn_utilities/citation/citation_aggregator.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ def _try_to_find_version(imported_module, module_name):
reference_entry[REFERENCES_VERSION_TYPE] = \
imported_module.version
elif hasattr(imported_module, "_version"):
# pylint: disable=protected-access
reference_entry[REFERENCES_VERSION_TYPE] = \
imported_module._version
return reference_entry
Expand Down
1 change: 0 additions & 1 deletion spinn_utilities/conf_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

# pylint: disable=too-many-arguments
import appdirs
import configparser
import logging
Expand Down
1 change: 1 addition & 0 deletions spinn_utilities/config_holder.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from spinn_utilities.configs import CamelCaseConfigParser
from spinn_utilities.log import FormatAdapter

# pylint: disable=global-statement
logger = FormatAdapter(logging.getLogger(__file__))

__config = None
Expand Down
3 changes: 1 addition & 2 deletions spinn_utilities/configs/camel_case_config_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import configparser
import distutils.util as _du # pylint: disable=import-error, no-name-in-module
import distutils.util as _du


class CamelCaseConfigParser(configparser.RawConfigParser):
Expand All @@ -32,7 +32,6 @@ def __init__(self, defaults=None, none_marker="None"):
self._none_marker = none_marker
self._read_files = list()

# pylint: disable=arguments-differ
def read(self, filenames, encoding=None):
""" Read and parse a filename or a list of filenames.
"""
Expand Down
3 changes: 1 addition & 2 deletions spinn_utilities/default_ordered_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

class DefaultOrderedDict(OrderedDict):
# Source: https://stackoverflow.com/questions/6190331
def __init__(self, default_factory=None, *args, **kwargs):
# pylint: disable=keyword-arg-before-vararg
def __init__(self, default_factory, *args, **kwargs):
if (default_factory is not None and
not isinstance(default_factory, Callable)):
raise TypeError('first argument must be callable')
Expand Down
5 changes: 2 additions & 3 deletions spinn_utilities/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,13 @@ def process(self, msg, kwargs):
Return the message and *kwargs* modified (or not) to suit your\
needs.
"""
# pylint: disable=deprecated-method
return msg, {
key: kwargs[key]
for key in getfullargspec(self.do_log).args[1:]
if key in kwargs}

@classmethod
def _atexit_handler(cls):
def atexit_handler(cls):
messages = cls._repeat_log()
if messages:
level = logging.getLevelName(cls.__repeat_at_end)
Expand Down Expand Up @@ -274,4 +273,4 @@ def _repeat_log(cls):
cls.__repeat_messages = []


atexit.register(FormatAdapter._atexit_handler)
atexit.register(FormatAdapter.atexit_handler)
2 changes: 1 addition & 1 deletion spinn_utilities/logger_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ def error_once(logger, msg):


def reset():
global _already_issued
global _already_issued # pylint: disable=global-statement
_already_issued = set()
15 changes: 7 additions & 8 deletions spinn_utilities/progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,11 +212,11 @@ def over(self, collection, finish_at_end=True):
def __new__(cls, *args, **kwargs): # @UnusedVariable
# pylint: disable=unused-argument
c = cls
if _EnhancedProgressBar._ENABLED:
if _EnhancedProgressBar._enabled:
if get_config_bool("Mode", "I_have_a_sense_of_humour"):
c = _EnhancedProgressBar
else:
_EnhancedProgressBar._ENABLED = False
_EnhancedProgressBar._enabled = False
return super().__new__(c)


Expand All @@ -227,7 +227,7 @@ class _EnhancedProgressBar(ProgressBar):
_line_no = 0
_seq_id = 0
_step_characters = defaultdict(list)
_ENABLED = False
_enabled = False
_DATA_FILE = "progress_bar.txt"

def _print_progress_unit(self, chars_to_print):
Expand Down Expand Up @@ -265,6 +265,7 @@ def __next_line(cls):

@classmethod
def init_once(cls):
cls._enabled = False
# read in the songs once for performance reasons
path = os.path.join(
os.path.dirname(os.path.realpath(spinn_utilities.__file__)),
Expand All @@ -280,7 +281,6 @@ def init_once(cls):
bits = line.split(":")
if len(bits) != 3:
# Bad data! Abort!
enabled = False
break
cls._step_characters[bits[0]].append(bits[1])

Expand All @@ -291,14 +291,13 @@ def init_once(cls):
step[_line_no] = step[_line_no].replace(" ", "_")

# verify that its a special day
enabled = date.today().strftime("%m%d") in cls._step_characters
cls._enabled = (
date.today().strftime("%m%d") in cls._step_characters)
except IOError:
cls._ENABLED = False
cls._seq_id = 0
finally:
cls._line_no = 0
cls._ENABLED = enabled
if enabled:
if cls._enabled:
cls._seq_id = date.today().strftime("%m%d")
else:
# To allow testing on a none special day
Expand Down
2 changes: 1 addition & 1 deletion spinn_utilities/ranged/range_dictionary.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def copy_into(self, other):
self._value_lists[key] = value.copy()
else:
self._value_lists[key] = RangedList(
value._size, key=key)
len(value), key=key)
self._value_lists[key].copy_into(value)

def copy(self):
Expand Down
1 change: 1 addition & 0 deletions spinn_utilities/ranged/ranged_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def __init__(
self._default = value
else:
self._default = None
self._ranged_based = None
self.set_value(value, use_list_as_value)

@overrides(AbstractList.range_based)
Expand Down
5 changes: 2 additions & 3 deletions spinn_utilities/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@
import sys
import time
from datetime import timedelta
# pylint: disable=no-name-in-module

if sys.version_info >= (3, 7):
# acquire the most accurate measurement available (perf_counter_ns)
_now = time.perf_counter_ns # pylint: disable=no-member
_now = time.perf_counter_ns
# conversion factor
_NANO_TO_MICRO = 1000.0

Expand All @@ -33,7 +32,7 @@ def _convert_to_timedelta(time_diff):

else:
# acquire the most accurate measurement available (perf_counter)
_now = time.perf_counter # pylint: disable=no-member
_now = time.perf_counter

def _convert_to_timedelta(time_diff):
""" Have to convert to a timedelta for rest of code to read.
Expand Down
6 changes: 3 additions & 3 deletions unittests/test_progress_bar.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from spinn_utilities.testing import log_checker
from spinn_utilities import logger_utils

EPB._ENABLED = False
EPB._enabled = False


@pytest.mark.parametrize("pbclass", [ProgressBar, DummyProgressBar, EPB])
Expand Down Expand Up @@ -94,8 +94,8 @@ def test_iteration_style(pbclass):
def test_bacon_enhancement(pbmagic):
unittest_setup()
try:
EPB._ENABLED = pbmagic
EPB._enabled = pbmagic
seq = (1, 2, 3)
assert sum(ProgressBar(seq, "foo").over(seq)) == 6
finally:
EPB._ENABLED = False
EPB._enabled = False

0 comments on commit 496ce4e

Please sign in to comment.