diff --git a/autopep8.py b/autopep8.py index 437c92f7..bcd36e15 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,6 +3969,16 @@ 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