Skip to content

Commit

Permalink
use custom warning format
Browse files Browse the repository at this point in the history
  • Loading branch information
hhatto committed May 29, 2024
1 parent 53a993e commit f516b29
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions autopep8.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class documentation for more information.
IS_SUPPORT_TOKEN_FSTRING = True


def _custom_formatwarning(message, category, _, __, line=None):
return f"{category.__name__}: {message}\n"


def open_with_encoding(filename, mode='r', encoding=None, limit_byte_check=-1):
"""Return opened file with a specific encoding."""
if not encoding:
Expand Down Expand Up @@ -3965,8 +3969,11 @@ def parse_args(arguments, apply_config=False):
'to the second',
)

original_formatwarning = warnings.formatwarning
warnings.formatwarning = _custom_formatwarning
if args.experimental:
warnings.warn("`experimental` option is deprecated and will be removed in a future version.", DeprecationWarning)
warnings.formatwarning = original_formatwarning

return args

Expand Down

0 comments on commit f516b29

Please sign in to comment.