Skip to content

Commit

Permalink
Fix Python 3.7 collections ABC classes deprecation warning
Browse files Browse the repository at this point in the history
Fixes #55
  • Loading branch information
jaimegildesagredo committed Oct 25, 2018
1 parent b29ca84 commit bb82213
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
14 changes: 9 additions & 5 deletions expects/matchers/built_in/contain.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# -*- coding: utf-8 -*

import functools
import collections

try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc

from .. import Matcher, default_matcher
from ...texts import plain_enumerate
Expand All @@ -10,9 +14,9 @@

class contain(Matcher):
_NON_NORMALIZED_SEQUENCE_TYPES = (
collections.Iterator,
collections.MappingView,
collections.Set
collections_abc.Iterator,
collections_abc.MappingView,
collections_abc.Set
)

def __init__(self, *expected):
Expand All @@ -35,7 +39,7 @@ def _match(self, subject):
return self._matches(subject)

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

def _matches(self, subject):
reasons = []
Expand Down
7 changes: 5 additions & 2 deletions expects/matchers/built_in/have_keys.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# -*- coding: utf-8 -*

import collections
try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc

from .. import Matcher, default_matcher
from ...texts import plain_enumerate
Expand All @@ -14,7 +17,7 @@ def _match(self, subject):
return self._matches(subject)

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

def _matches(self, subject):
args, kwargs = self._expected
Expand Down
7 changes: 6 additions & 1 deletion expects/matchers/built_in/start_end_with.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import collections

try:
import collections.abc as collections_abc
except ImportError:
import collections as collections_abc

from .. import Matcher
from ...texts import plain_enumerate
from ... import _compat
Expand All @@ -19,7 +24,7 @@ def _match(self, subject):

def _is_unordered_dict(self, subject):
return (
isinstance(subject, collections.Mapping) and
isinstance(subject, collections_abc.Mapping) and
not isinstance(subject, collections.OrderedDict)
)

Expand Down

0 comments on commit bb82213

Please sign in to comment.