From f516b2971af28c5ffa218694d94d9af318c79666 Mon Sep 17 00:00:00 2001 From: Hideo Hattori Date: Wed, 29 May 2024 09:51:37 +0900 Subject: [PATCH] use custom warning format --- autopep8.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/autopep8.py b/autopep8.py index 31be3a48..78d2e7dc 100755 --- a/autopep8.py +++ b/autopep8.py @@ -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: @@ -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