Skip to content

Commit 36712d6

Browse files
authored
Fix ads import crash when IPython is installed without an active shell (#1355)
1 parent d0a30a4 commit 36712d6

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

ads/common/ipython.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8; -*-
32

4-
# Copyright (c) 2022 Oracle and/or its affiliates.
3+
# Copyright (c) 2022, 2026 Oracle and/or its affiliates.
54
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl/
65

76
import logging
@@ -63,12 +62,14 @@ def configure_plotting():
6362

6463
try:
6564
import IPython
65+
6666
shell = IPython.get_ipython()
67-
global orig_ipython_traceback
68-
if shell.showtraceback != _log_traceback:
69-
orig_ipython_traceback = shell.showtraceback
67+
if shell is not None:
68+
global orig_ipython_traceback
69+
if shell.showtraceback != _log_traceback:
70+
orig_ipython_traceback = shell.showtraceback
7071

71-
# Override the default showtraceback behavior of ipython, to show only the error message and log the stacktrace
72-
shell.showtraceback = _log_traceback
72+
# Override the default showtraceback behavior of ipython, to show only the error message and log the stacktrace
73+
shell.showtraceback = _log_traceback
7374
except ModuleNotFoundError:
7475
pass

0 commit comments

Comments
 (0)