Skip to content

Commit

Permalink
solve ANSI escape sequences print error in cmd and powershell
Browse files Browse the repository at this point in the history
  • Loading branch information
thisjiang committed Jun 21, 2021
1 parent f88af20 commit c882a7a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions python/paddle/fluid/dygraph/varbase_patch_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import numpy as np
import warnings
import weakref
import sys

import paddle
from .. import framework
Expand Down Expand Up @@ -372,6 +373,9 @@ def grad(self):
"""
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()

Expand Down
5 changes: 5 additions & 0 deletions python/paddle/utils/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import warnings
import functools
import paddle
import sys

__all__ = []

Expand Down Expand Up @@ -99,6 +100,10 @@ def wrapper(*args, **kwargs):
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(".")]
Expand Down

1 comment on commit c882a7a

@paddle-bot-old
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congratulation! Your pull request passed all required CI. You could ask reviewer(s) to approve and merge. 🎉

Please sign in to comment.