Skip to content

Commit

Permalink
fix: remove warning from collections usage
Browse files Browse the repository at this point in the history
  • Loading branch information
cpcloud committed Nov 24, 2021
1 parent 513ab58 commit 7e0847e
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions protoletariat/rewrite.py
Expand Up @@ -2,6 +2,7 @@

import ast
import collections
import collections.abc
from typing import Any, Callable, NamedTuple, Sequence, Union

Node = Union[ast.AST, Sequence[ast.AST]]
Expand All @@ -13,7 +14,7 @@ class Replacement(NamedTuple):


def _is_iterable(value: Any) -> bool:
return not isinstance(value, str) and isinstance(value, collections.Iterable)
return not isinstance(value, str) and isinstance(value, collections.abc.Iterable)


def matches(value: Node, pattern: Node) -> bool:
Expand All @@ -33,10 +34,10 @@ def matches(value: Node, pattern: Node) -> bool:
# recur into lists
if _is_iterable(value) and _is_iterable(pattern):
assert isinstance(
value, collections.Iterable
value, collections.abc.Iterable
), f"value is not a non-str iterable {type(value).__name__}"
assert isinstance(
pattern, collections.Iterable
pattern, collections.abc.Iterable
), f"pattern is not a non-str iterable {type(pattern).__name__}"
return all(map(matches, value, pattern))

Expand Down

0 comments on commit 7e0847e

Please sign in to comment.