Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import ABC from collections.abc #288

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions texar/tf/modules/encoders/hierarchical_encoders.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
Various encoders that encode data with hierarchical structure.
"""

import collections
import collections.abc

import tensorflow as tf
from tensorflow.contrib.rnn import LSTMStateTuple
Expand Down Expand Up @@ -256,7 +256,7 @@ def _kwargs_split(kwargs):
if medium is None:
states_minor = self.flatten(states_minor)
else:
if not isinstance(medium, collections.Sequence):
if not isinstance(medium, collections.abc.Sequence):
medium = [medium]
for fn in medium:
if isinstance(fn, str) and fn == 'flatten':
Expand Down Expand Up @@ -355,7 +355,7 @@ def flatten(x):
"""
if isinstance(x, LSTMStateTuple):
return x.h
if isinstance(x, collections.Sequence):
if isinstance(x, collections.abc.Sequence):
return tf.concat(
[HierarchicalRNNEncoder.flatten(v) for v in x], -1)
else:
Expand Down
3 changes: 2 additions & 1 deletion texar/tf/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
from pydoc import locate
import copy
import collections
import collections.abc
import numpy as np

import tensorflow as tf
Expand Down Expand Up @@ -577,7 +578,7 @@ def flatten_dict(dict_, parent_key="", sep="."):
items = []
for key, value in dict_.items():
key_ = parent_key + sep + key if parent_key else key
if isinstance(value, collections.MutableMapping):
if isinstance(value, collections.abc.MutableMapping):
items.extend(flatten_dict(value, key_, sep=sep).items())
elif isinstance(value, tuple) and hasattr(value, "_asdict"):
dict_items = collections.OrderedDict(zip(value._fields, value))
Expand Down