myint / pyformat

Formats Python code to follow a consistent style
https://pypi.python.org/pypi/pyformat
94 stars 10 forks source link

UnicodeEncodeError #1

Closed ponty closed 11 years ago

ponty commented 11 years ago
$ cat unicode.py 
#!/usr/bin/python
# -*- coding: utf-8 -*-

'ö'
$ autopep8 -i unicode.py
$ pyformat -i unicode.py 
Traceback (most recent call last):
  File "/usr/local/bin/pyformat", line 42, in <module>
    standard_error=sys.stderr))
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 179, in main
    format_multiple_files(set(args.files), args, standard_out, standard_error)
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 126, in format_multiple_files
    _format_file((name, args, standard_out, standard_error))
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 104, in _format_file
    format_file(*parameters[:-1])
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 79, in format_file
    formatted_source = format_code(source, aggressive=args.aggressive)
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 64, in format_code
    formatted_source = fix(formatted_source)
  File "/usr/local/lib/python2.7/dist-packages/pyformat.py", line 54, in <lambda>
    yield lambda code: autopep8.fix_string(code, options=autopep8_options)
  File "/usr/local/lib/python2.7/dist-packages/autopep8.py", line 1941, in fix_string
    source = source.decode(locale.getpreferredencoding(False))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 44: ordinal not in range(128)
myint commented 11 years ago

I can reproduce this. I'll take a look.

myint commented 11 years ago

I've fixed this in the latest autopep8.

$ pip install --upgrade git+https://github.com/hhatto/autopep8

Thanks for the report!