Skip to content

Commit

Permalink
Merge pull request #56 from jdlourenco/collections-abc-six
Browse files Browse the repository at this point in the history
Fix collections.abc deprecation warning by using six.moves.collections_abc
  • Loading branch information
h2non committed Feb 25, 2020
2 parents 1caa121 + b3d4bac commit 35878a0
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 21 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Expand Up @@ -2,10 +2,10 @@ language: python

python:
- "2.7"
- "3.3"
- "3.4"
- "3.5"
- "3.6"
- "3.7"
- "3.8"
- pypy
- pypy3
- nightly
Expand Down
2 changes: 1 addition & 1 deletion grappa/api.py
Expand Up @@ -9,7 +9,7 @@
# Expose config module as part of the public API
from .config import config
# Expose decorator for operators factory
from .decorators import * # noqa
from .decorators import operator, register, attribute
# Expose Operatocdr base class
from .operator import Operator
# Required to load built-in operators
Expand Down
10 changes: 5 additions & 5 deletions grappa/operators/contain.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import collections
from six.moves import collections_abc
import six
from ..operator import Operator

Expand Down Expand Up @@ -57,9 +57,9 @@ class ContainOperator(Operator):

# Stores types to normalize before the assertion
NORMALIZE_TYPES = (
collections.Iterator,
collections.MappingView,
collections.Set
collections_abc.Iterator,
collections_abc.MappingView,
collections_abc.Set
)

def match(self, subject, *expected):
Expand All @@ -72,7 +72,7 @@ def match(self, subject, *expected):
return self._matches(subject, *expected)

def _is_not_a_sequence(self, value):
return not isinstance(value, collections.Sequence)
return not isinstance(value, collections_abc.Sequence)

def _matches(self, subject, *expected):
reasons = []
Expand Down
2 changes: 1 addition & 1 deletion grappa/operators/empty.py
Expand Up @@ -60,7 +60,7 @@ class EmptyOperator(Operator):
)

def match(self, subject):
if subject is None or subject is 0:
if subject is None or subject is 0: # noqa F632
return True

if subject in (True, False):
Expand Down
4 changes: 2 additions & 2 deletions grappa/operators/keys.py
@@ -1,5 +1,5 @@
# -*- coding: utf-8 -*-
import collections
from six.moves import collections_abc

from ..operator import Operator

Expand Down Expand Up @@ -60,7 +60,7 @@ def match(self, subject, *keys, **kw):
return self._matches(subject, (keys, kw))

def _not_a_dict(self, value):
return not isinstance(value, collections.Mapping)
return not isinstance(value, collections_abc.Mapping)

def _matches(self, subject, expected):
args, kwargs = expected
Expand Down
2 changes: 1 addition & 1 deletion grappa/operators/length.py
Expand Up @@ -83,7 +83,7 @@ def on_access(self, subject):
try:
self.ctx.subject = len(subject)
self.ctx.length = False
except:
except Exception:
return False, ['cannot measure length of the given object']

return True, []
Expand Down
8 changes: 4 additions & 4 deletions grappa/operators/match.py
Expand Up @@ -12,22 +12,22 @@ class MatchOperator(Operator):
Example::
# Should style
'hello world' | should.match(r'Hello \w+')
'hello world' | should.match(r'Hello \\w+')
'hello world' | should.match(r'hello [A-Z]+', re.I))
'hello world' | should.match.expression(r'hello [A-Z]+', re.I))
# Should style - negation form
'hello w0rld' | should.do_not.match(r'Hello \w+')
'hello w0rld' | should.do_not.match(r'Hello \\w+')
'hello w0rld' | should.do_not.match(r'hello [A-Z]+', re.I))
'hello world' | should.do_not.match.expression(r'hello [A-Z]+', re.I))
# Expect style
'hello world' | expect.to.match(r'Hello \w+')
'hello world' | expect.to.match(r'Hello \\w+')
'hello world' | expect.to.match(r'hello [A-Z]+', re.I))
'hello world' | expect.to.match.expression(r'hello [A-Z]+', re.I))
# Expect style - negation form
'hello w0rld' | expect.to_not.match(r'Hello \w+')
'hello w0rld' | expect.to_not.match(r'Hello \\w+')
'hello w0rld' | expect.to_not.match(r'hello [A-Z]+', re.I))
'hello world' | expect.to_not.match.expression(r'hello [A-Z]+', re.I))
"""
Expand Down
3 changes: 2 additions & 1 deletion grappa/operators/start_end.py
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import collections
from six.moves import collections_abc

from ..operator import Operator
from ..constants import STR_TYPES
Expand All @@ -23,7 +24,7 @@ def match(self, subject, *expected):
return self.matches(subject, *expected)

def is_unordered_dict(self, subject):
if isinstance(subject, collections.Mapping):
if isinstance(subject, collections_abc.Mapping):
if not hasattr(collections, 'OrderedDict'):
return True
return not isinstance(subject, collections.OrderedDict)
Expand Down
4 changes: 2 additions & 2 deletions grappa/reporters/base.py
Expand Up @@ -30,7 +30,7 @@ def normalize(self, value, size=20, use_raw=True):

try:
value = str(value)
except:
except: # noqa E722
value = value

if not hasattr(value, '__len__'):
Expand All @@ -50,7 +50,7 @@ def normalize(self, value, size=20, use_raw=True):
def safe_length(self, value):
try:
return len(value)
except:
except: # noqa E722
return '"unmeasurable"'

def from_operator(self, name, defaults=None, operator=None):
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
@@ -1,5 +1,5 @@
coveralls~=1.1
flake8~=3.3.0
flake8~=3.7.9
pytest~=3.0.3
pytest-cov~=2.4.0
pytest-flakes~=1.0.1
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,2 +1,2 @@
colorama>=0.3.9,<2
six~=1.11
six~=1.14

0 comments on commit 35878a0

Please sign in to comment.