From 182842617ce5ca4ab72ef2d8e0d6c562e04ce7eb Mon Sep 17 00:00:00 2001 From: jiangcheng Date: Tue, 22 Jun 2021 10:34:26 +0800 Subject: [PATCH] solve ANSI escape sequences print error in cmd and powershell (#33689) --- python/paddle/fluid/dygraph/varbase_patch_methods.py | 4 ++++ python/paddle/utils/deprecated.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/python/paddle/fluid/dygraph/varbase_patch_methods.py b/python/paddle/fluid/dygraph/varbase_patch_methods.py index 644e25ab918..17cd499bfee 100644 --- a/python/paddle/fluid/dygraph/varbase_patch_methods.py +++ b/python/paddle/fluid/dygraph/varbase_patch_methods.py @@ -16,6 +16,7 @@ import inspect import numpy as np import warnings import weakref +import sys import paddle from .. import framework @@ -372,6 +373,9 @@ def monkey_patch_varbase(): """ msg = "tensor.grad will return the tensor value of the gradient." warning_msg = "\033[93m\nWarning:\n%s \033[0m" % (msg) + # ensure ANSI escape sequences print correctly in cmd and powershell + if sys.platform.lower() == 'win32': + warning_msg = "\nWarning:\n%s " % (msg) warnings.warn(warning_msg) return self._grad_ivar() diff --git a/python/paddle/utils/deprecated.py b/python/paddle/utils/deprecated.py index e3839d9767d..b17bd70c91a 100755 --- a/python/paddle/utils/deprecated.py +++ b/python/paddle/utils/deprecated.py @@ -18,6 +18,7 @@ decorator to deprecate a function or class import warnings import functools import paddle +import sys __all__ = [] @@ -99,6 +100,10 @@ def deprecated(update_to="", since="", reason="", level=0): func.__module__, func.__name__)) warningmsg = "\033[93m\nWarning:\n%s \033[0m" % (msg) + # ensure ANSI escape sequences print correctly in cmd and powershell + if sys.platform.lower() == 'win32': + warningmsg = "\nWarning:\n%s " % (msg) + v_current = [int(i) for i in paddle.__version__.split(".")] v_current += [0] * (4 - len(v_current)) v_since = [int(i) for i in _since.split(".")] -- GitLab