Skip to content
Merged
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
19 changes: 12 additions & 7 deletions box/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@
except ImportError:
from collections.abc import Callable, Iterable, Mapping

try:
from IPython import get_ipython
except ImportError:
ipython = False
else:
ipython = True if get_ipython() else False

import box
from box.converters import (
Expand Down Expand Up @@ -56,6 +50,17 @@
NO_NAMESPACE = object()


def _is_ipython():
try:
from IPython import get_ipython
except ImportError:
ipython = False
else:
ipython = True if get_ipython() else False

return ipython


def _exception_cause(e):
"""
Unwrap BoxKeyError and BoxValueError errors to their cause.
Expand Down Expand Up @@ -483,7 +488,7 @@ def __setstate__(self, state):
self.__dict__.update(state)

def __get_default(self, item, attr=False):
if ipython and item in ("getdoc", "shape"):
if item in ("getdoc", "shape") and _is_ipython():
return None
default_value = self._box_config["default_box_attr"]
if default_value in (self._box_config["box_class"], dict):
Expand Down