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

[Error] [ipython] Use print directly instead of builtin warnings module to prevent being supressed #1969

Merged
merged 1 commit into from
Oct 17, 2020
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
18 changes: 9 additions & 9 deletions python/taichi/misc/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,18 +110,18 @@ def get_line_number(asc=0):
return inspect.stack()[1 + asc][2]


# The builtin `warnings` module is unreliable as it may be supressed
# by other packages, e.g. IPython.
def warning(msg, type=UserWarning, stacklevel=1):
import warnings
from colorama import Fore, Back, Style
import traceback
import taichi as ti
use_spdlog = False
if use_spdlog:
s = traceback.extract_stack()[:-stacklevel]
raw = ''.join(traceback.format_list(s))
ti.warn(f'{type.__name__}: {msg}')
ti.warn(f'\n{raw}')
else:
warnings.warn(msg, type, stacklevel=stacklevel + 1)
s = traceback.extract_stack()[:-stacklevel]
raw = ''.join(traceback.format_list(s))
print(Fore.YELLOW + Style.BRIGHT, end='')
print(f'{type.__name__}: {msg}')
print(f'\n{raw}')
print(Style.RESET_ALL, end='')


def deprecated(old, new, type=DeprecationWarning):
Expand Down