diff --git a/google/colab/_reprs.py b/google/colab/_reprs.py index 0f0d6750..8f255fe4 100644 --- a/google/colab/_reprs.py +++ b/google/colab/_reprs.py @@ -14,12 +14,15 @@ import numpy as np import PIL as pil # pylint: disable=g-import-not-at-top -with warnings.catch_warnings(): - # Importing via IPython raises a spurious warning, but avoids a version - # mismatch internally. - warnings.simplefilter('ignore') - from IPython.utils import traitlets - +# TODO(b/210783561): Keep both imports as we migrate to IPython 7 +try: + with warnings.catch_warnings(): + # Importing via IPython raises a spurious warning, but avoids a version + # mismatch internally. + warnings.simplefilter('ignore') + from IPython.utils import traitlets +except ImportError: + import traitlets _original_string_formatters = {} diff --git a/google/colab/data_table.py b/google/colab/data_table.py index 07a94593..2c9a747b 100644 --- a/google/colab/data_table.py +++ b/google/colab/data_table.py @@ -34,15 +34,18 @@ from IPython import display as _display import packaging.version as _version - # pylint: disable=g-import-not-at-top -with _warnings.catch_warnings(): - # Importing via IPython raises a spurious warning, but avoids a version - # mismatch internally. - _warnings.simplefilter('ignore') - from IPython.utils import traitlets as _traitlets - -# pylint: enable=g-import-not-at-top +# TODO(b/210783561): Keep both imports as we migrate to IPython 7 +try: + with _warnings.catch_warnings(): + # Importing via IPython raises a spurious warning, but avoids a version + # mismatch internally. + _warnings.simplefilter('ignore') + from IPython.utils import traitlets as _traitlets +except ImportError: + # pytype: disable=import-error + import traitlets as _traitlets + # pytype: enable=import-error __all__ = [ 'DataTable',