Skip to content

Commit b247d30

Browse files
committed
solve ANSI escape sequences print error in cmd and powershell (#33689)
1 parent cdeffff commit b247d30

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

python/paddle/fluid/dygraph/varbase_patch_methods.py

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import numpy as np
1717
import warnings
1818
import weakref
19+
import sys
1920

2021
import paddle
2122
from .. import framework
@@ -372,6 +373,9 @@ def grad(self):
372373
"""
373374
msg = "tensor.grad will return the tensor value of the gradient."
374375
warning_msg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
376+
# ensure ANSI escape sequences print correctly in cmd and powershell
377+
if sys.platform.lower() == 'win32':
378+
warning_msg = "\nWarning:\n%s " % (msg)
375379
warnings.warn(warning_msg)
376380
return self._grad_ivar()
377381

python/paddle/utils/deprecated.py

+5
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import warnings
1919
import functools
2020
import paddle
21+
import sys
2122

2223
__all__ = []
2324

@@ -99,6 +100,10 @@ def wrapper(*args, **kwargs):
99100
func.__module__, func.__name__))
100101

101102
warningmsg = "\033[93m\nWarning:\n%s \033[0m" % (msg)
103+
# ensure ANSI escape sequences print correctly in cmd and powershell
104+
if sys.platform.lower() == 'win32':
105+
warningmsg = "\nWarning:\n%s " % (msg)
106+
102107
v_current = [int(i) for i in paddle.__version__.split(".")]
103108
v_current += [0] * (4 - len(v_current))
104109
v_since = [int(i) for i in _since.split(".")]

0 commit comments

Comments
 (0)