diff --git a/rebulk/chain.py b/rebulk/chain.py index 9a7850b..dfb6ea4 100644 --- a/rebulk/chain.py +++ b/rebulk/chain.py @@ -300,14 +300,14 @@ def _truncate_chain_part_matches(is_chain_start, chain_part_matches, chain_part, if not is_chain_start: separator = chain_input_string[0:chain_part_matches[0].initiator.raw_start] - if len(separator) > 0: + if separator: return [] j = 1 for i in range(0, len(chain_part_matches) - 1): separator = chain_input_string[chain_part_matches[i].initiator.raw_end: chain_part_matches[i + 1].initiator.raw_start] - if len(separator) > 0: + if separator: break j += 1 truncated = chain_part_matches[:j] diff --git a/rebulk/match.py b/rebulk/match.py index d9eef5c..b790b41 100644 --- a/rebulk/match.py +++ b/rebulk/match.py @@ -38,7 +38,7 @@ class _BaseMatches(MutableSequence): _base_remove = _base.remove _base_extend = _base.extend - def __init__(self, matches=None, input_string=None): + def __init__(self, matches=None, input_string=None): # pylint: disable=super-init-not-called self.input_string = input_string self._max_end = 0 self._delegate = [] @@ -561,9 +561,9 @@ def __delitem__(self, index): def __repr__(self): return self._delegate.__repr__() - def insert(self, index, match): - self._delegate.insert(index, match) - self._add_match(match) + def insert(self, index, value): + self._delegate.insert(index, value) + self._add_match(value) class Matches(_BaseMatches): @@ -671,12 +671,11 @@ def names(self): """ if not self.children: return set([self.name]) - else: - ret = set() - for child in self.children: - for name in child.names: - ret.add(name) - return ret + ret = set() + for child in self.children: + for name in child.names: + ret.add(name) + return ret @property def raw_start(self): @@ -768,10 +767,10 @@ def crop(self, crops, predicate=None, index=None): # crop is included in self, split current ... right = copy.deepcopy(current) current.end = start - if len(current) <= 0: + if not current: ret.remove(current) right.start = end - if len(right) > 0: + if right: ret.append(right) elif end <= current.end and end > current.start: current.start = end diff --git a/rebulk/pattern.py b/rebulk/pattern.py index c5b3cce..57b274e 100644 --- a/rebulk/pattern.py +++ b/rebulk/pattern.py @@ -136,7 +136,7 @@ def _match_parent(self, match, yield_parent): :return: :rtype: """ - if len(match) == 0 or match.value == "": + if not match or match.value == "": return False pattern_value = get_first_defined(self.values, [match.name, '__parent__', None], @@ -164,7 +164,7 @@ def _match_child(self, child, yield_children): :return: :rtype: """ - if len(child) == 0 or child.value == "": + if not child or child.value == "": return False pattern_value = get_first_defined(self.values, [child.name, '__children__', None], diff --git a/rebulk/processors.py b/rebulk/processors.py index 0121c65..b9fa52b 100644 --- a/rebulk/processors.py +++ b/rebulk/processors.py @@ -51,6 +51,7 @@ def default_conflict_solver(self): # pylint:disable=no-self-use return _default_conflict_solver def when(self, matches, context): + # pylint:disable=too-many-nested-blocks to_remove_matches = IdentitySet() public_matches = [match for match in matches if not match.private] diff --git a/rebulk/test/default_rules_module.py b/rebulk/test/default_rules_module.py index 5eed8e0..065e161 100644 --- a/rebulk/test/default_rules_module.py +++ b/rebulk/test/default_rules_module.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition from ..match import Match from ..rules import Rule, RemoveMatch, AppendMatch, RenameMatch, AppendTags, RemoveTags diff --git a/rebulk/test/rebulk_rules_module.py b/rebulk/test/rebulk_rules_module.py index 0bd5ef3..177e4a9 100644 --- a/rebulk/test/rebulk_rules_module.py +++ b/rebulk/test/rebulk_rules_module.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition from rebulk.rules import Rule, RemoveMatch, CustomRule diff --git a/rebulk/test/rules_module.py b/rebulk/test/rules_module.py index 887b81d..8814a68 100644 --- a/rebulk/test/rules_module.py +++ b/rebulk/test/rules_module.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition from ..match import Match from ..rules import Rule diff --git a/rebulk/test/test_chain.py b/rebulk/test/test_chain.py index 6d89755..2715abc 100644 --- a/rebulk/test/test_chain.py +++ b/rebulk/test/test_chain.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member +# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member, len-as-condition import re from functools import partial diff --git a/rebulk/test/test_debug.py b/rebulk/test/test_debug.py index a35f95f..cd9e556 100644 --- a/rebulk/test/test_debug.py +++ b/rebulk/test/test_debug.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, protected-access, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, protected-access, invalid-name, len-as-condition from ..pattern import StringPattern from ..rebulk import Rebulk diff --git a/rebulk/test/test_introspector.py b/rebulk/test/test_introspector.py index 24c0c50..d83360f 100644 --- a/rebulk/test/test_introspector.py +++ b/rebulk/test/test_introspector.py @@ -3,7 +3,7 @@ """ Introspector tests """ -# pylint: disable=no-self-use,pointless-statement,missing-docstring,protected-access,invalid-name +# pylint: disable=no-self-use,pointless-statement,missing-docstring,protected-access,invalid-name,len-as-condition from ..rebulk import Rebulk from .. import introspector from .default_rules_module import RuleAppend2, RuleAppend3 diff --git a/rebulk/test/test_loose.py b/rebulk/test/test_loose.py index bc0c6bc..d54e6bc 100644 --- a/rebulk/test/test_loose.py +++ b/rebulk/test/test_loose.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, len-as-condition from ..loose import call diff --git a/rebulk/test/test_match.py b/rebulk/test/test_match.py index efbc63d..ea054d9 100644 --- a/rebulk/test/test_match.py +++ b/rebulk/test/test_match.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, unneeded-not +# pylint: disable=no-self-use, pointless-statement, missing-docstring, unneeded-not, len-as-condition import pytest import six diff --git a/rebulk/test/test_pattern.py b/rebulk/test/test_pattern.py index 6879d0c..beee170 100644 --- a/rebulk/test/test_pattern.py +++ b/rebulk/test/test_pattern.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, unbalanced-tuple-unpacking +# pylint: disable=no-self-use, pointless-statement, missing-docstring, unbalanced-tuple-unpacking, len-as-condition import re import pytest @@ -396,10 +396,10 @@ def test_matches_kwargs(self): children = matches[0].children assert len(children) == 2 - assert children[0].name is "test" + assert children[0].name == "test" assert children[0].value == "HE" - assert children[1].name is "test" + assert children[1].name == "test" assert children[1].value == "HE" pattern = RePattern("H(?Pe.)(?Prew)", name="test", value="HE") @@ -807,8 +807,7 @@ def test_validate_all(self): def invalid_func(match): if match.name == 'intParam': return True - else: - return match.value.startswith('abc') + return match.value.startswith('abc') pattern = RePattern(r"contains (?P\d+)", formatter=int, validator=invalid_func, validate_all=True, children=True) @@ -819,8 +818,7 @@ def invalid_func(match): def func(match): if match.name == 'intParam': return True - else: - return match.value.startswith('contains') + return match.value.startswith('contains') pattern = RePattern(r"contains (?P\d+)", formatter=int, validator=func, validate_all=True, children=True) diff --git a/rebulk/test/test_processors.py b/rebulk/test/test_processors.py index 7afd453..69be20f 100644 --- a/rebulk/test/test_processors.py +++ b/rebulk/test/test_processors.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member +# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member, len-as-condition from ..pattern import StringPattern, RePattern from ..processors import ConflictSolver diff --git a/rebulk/test/test_rebulk.py b/rebulk/test/test_rebulk.py index bf0bc96..bafa01d 100644 --- a/rebulk/test/test_rebulk.py +++ b/rebulk/test/test_rebulk.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member +# pylint: disable=no-self-use, pointless-statement, missing-docstring, no-member, len-as-condition from ..rebulk import Rebulk from ..rules import Rule diff --git a/rebulk/test/test_rules.py b/rebulk/test/test_rules.py index 47b6f5f..cd7c0dd 100644 --- a/rebulk/test/test_rules.py +++ b/rebulk/test/test_rules.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, no-member +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name, no-member, len-as-condition import pytest from rebulk.test.default_rules_module import RuleRemove0, RuleAppend0, RuleRename0, RuleAppend1, RuleRemove1, \ RuleRename1, RuleAppend2, RuleRename2, RuleAppend3, RuleRename3, RuleAppendTags0, RuleRemoveTags0, \ diff --git a/rebulk/test/test_validators.py b/rebulk/test/test_validators.py index 38511cb..863ec09 100644 --- a/rebulk/test/test_validators.py +++ b/rebulk/test/test_validators.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- -# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name +# pylint: disable=no-self-use, pointless-statement, missing-docstring, invalid-name,len-as-condition from functools import partial diff --git a/rebulk/utils.py b/rebulk/utils.py index 73d7dce..9aaf56d 100644 --- a/rebulk/utils.py +++ b/rebulk/utils.py @@ -83,6 +83,7 @@ def is_iterable(obj): We don't need to check for the Python 2 `unicode` type, because it doesn't have an `__iter__` attribute anyway. """ + # pylint: disable=consider-using-ternary return hasattr(obj, '__iter__') and not isinstance(obj, str) or isinstance(obj, GeneratorType) @@ -117,7 +118,7 @@ class IdentitySet(MutableSet): # pragma: no cover """ Set based on identity """ - def __init__(self, items=None): + def __init__(self, items=None): # pylint: disable=super-init-not-called if items is None: items = [] self.refs = set(map(_Ref, items)) @@ -131,11 +132,11 @@ def __iter__(self): def __len__(self): return len(self.refs) - def add(self, elem): - self.refs.add(_Ref(elem)) + def add(self, value): + self.refs.add(_Ref(value)) - def discard(self, elem): - self.refs.discard(_Ref(elem)) + def discard(self, value): + self.refs.discard(_Ref(value)) def update(self, iterable): """