Skip to content

Commit

Permalink
Merge 375fcb4 into b06b3ee
Browse files Browse the repository at this point in the history
  • Loading branch information
Toilal committed May 31, 2017
2 parents b06b3ee + 375fcb4 commit d8284b0
Show file tree
Hide file tree
Showing 19 changed files with 43 additions and 43 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ python:
- 3.3
- 3.4
- 3.5
- 3.6
- pypy
install:
- pip install -r requirements.txt
- pip install pytest>=2.7.3 --upgrade
- pip install pylint
- pip install pip --upgrade
- pip install -e .[dev,test]
- pip install pytest --upgrade
- pip install coveralls
script:
- if [ $TRAVIS_PYTHON_VERSION != 2.6 ]; then pylint rebulk; fi
Expand Down
4 changes: 2 additions & 2 deletions rebulk/chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
23 changes: 11 additions & 12 deletions rebulk/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rebulk/pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down Expand Up @@ -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],
Expand Down
1 change: 1 addition & 0 deletions rebulk/processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/default_rules_module.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/rebulk_rules_module.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/rules_module.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_chain.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_debug.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_introspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_loose.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_match.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
12 changes: 5 additions & 7 deletions rebulk/test/test_pattern.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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(?P<first>e.)(?P<second>rew)", name="test", value="HE")
Expand Down Expand Up @@ -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<intParam>\d+)", formatter=int, validator=invalid_func, validate_all=True,
children=True)
Expand All @@ -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<intParam>\d+)", formatter=int, validator=func, validate_all=True,
children=True)
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_processors.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_rebulk.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_rules.py
Original file line number Diff line number Diff line change
@@ -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, \
Expand Down
2 changes: 1 addition & 1 deletion rebulk/test/test_validators.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
11 changes: 6 additions & 5 deletions rebulk/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down Expand Up @@ -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))
Expand All @@ -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):
"""
Expand Down

0 comments on commit d8284b0

Please sign in to comment.