hhatto / autopep8

A tool that automatically formats Python code to conform to the PEP 8 style guide.

Home Page:https://pypi.org/project/autopep8/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

formatter does not work if it contains a specific string

LCH-1 opened this issue · comments

commented

Python Code

YOUR CODE

# normal case
def test():
    pass
def test2():
    pass

# issue case
def test():
    # テスト
    pass
def test2():
    pass

Command Line and Configuration

.pep8, setup.cfg, (using default setting)

[pep8]

Command Line(in windows cmd)

type test.py | python -m autopep8 -

Your Environment

  • Python version: 3.11.1
  • autopep8 version: 2.0.1
  • Platform: windows11

An issue occurred while using autopep8 extension in vscode. (microsoft/vscode-autopep8#51)

Normally, it works fine.
But it doesn't work if it contains specific characters.

issue

(venv) C:\Users\user\Desktop\test>type test.py | python -m autopep8 -
Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "C:\Users\user\Desktop\test\venv\Lib\site-packages\autopep8.py", line 4560, in <module>
    sys.exit(main())
             ^^^^^^
  File "C:\Users\user\Desktop\test\venv\Lib\site-packages\autopep8.py", line 4506, in main
    wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
UnicodeEncodeError: 'cp949' codec can't encode character '\udce3' in position 18: illegal multibyte sequence

(venv) C:\Users\user\Desktop\test>

Thank you

Same issue with Chinese characters

UnicodeEncodeError: 'gbk' codec can't encode character '\udcb0' in position 450: illegal multibyte sequence

Same issue happens in Korean characters

2023-05-21 18:08:06.772 [info] [Trace - 오후 6:08:06] Received notification 'window/logMessage'.
2023-05-21 18:08:06.772 [info] Traceback (most recent call last):
  File "c:\Users\heeyong\miniconda3\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "c:\Users\heeyong\miniconda3\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "c:\Users\heeyong\.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4570, in <module>
    sys.exit(main())
  File "c:\Users\heeyong\.vscode\extensions\ms-python.autopep8-2023.4.0\bundled\libs\autopep8.py", line 4516, in main
    wrap_output(sys.stdout, encoding=encoding).write(fixed_stdin)
UnicodeEncodeError: 'cp949' codec can't encode character '\udcec' in position 275: illegal multibyte sequence

2023-05-21 18:08:06.772 [info] [Trace - 오후 6:08:06] Received response 'textDocument/formatting - (1)' in 239ms.
2023-05-21 18:10:14.248 [info] [Trace - 오후 6:10:14] Sending notification 'textDocument/didOpen'.
commented

This issue appears to have been resolved by microsoft/vscode-autopep8@91b79ef.