I'm Hideo Hattori.
hhatto / autopep8 Goto Github PK
View Code? Open in Web Editor NEWA tool that automatically formats Python code to conform to the PEP 8 style guide.
Home Page: https://pypi.org/project/autopep8/
License: MIT License
A tool that automatically formats Python code to conform to the PEP 8 style guide.
Home Page: https://pypi.org/project/autopep8/
License: MIT License
Hello,
I'm the current maintainer of pep8.py
.
In order to make the library more flexible, I removed the global configuration.
Unfortunately, I cannot easily preserve the compatibility with previous version.
You can checkout the current 1.3 alpha1 and have a look.
I plan to release 1.3 later this week, or next week.
Florent
I don't know what causes autopep8 to not fix the files, as I am also using it in another project without any problems,
Here how I call it:
autopep8 --ignore=E501 -i .py scripts/.py scripts//.py scripts/contrib/jira/jira.py
autopep8: 0.8.2
pep8: 1.3.3
pep8 reports tons of things to fix, including mixed tab/spaces issue which were solved by autopep8 without any problems.
Running it with "-v" displays few things to fix, but not as many as expected, still it does not fix them.
---> 30 issue(s) to fix {'W191': set([8, 10]), 'E101': set([16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43])}
here is the setup of pep8 (.pep8 file):
[pep8]
exclude=.svn,CVS,.bzr,.hg,.git,lib,.tox,third,*.egg,temp,plugins,textile.py,old,SOAPpy,fpconst,sqlalchemy,tendo,unittest2,wstools,requests_oauth
ignore=E501 scripts
max-line-length=1024
count=1
statistics=1
pep8 reports ~1500 things to fix.
Would be nice also to split long lines to newline automatically.
autopep8 works incorrectly with CRLF endings in windows
for example
def abc(): {CRLF}
print "123"
will be transformed to
def abc(): {CR}
{CRLF}
print "123"
test.py:
i **2
i *2
$ autopep8 test.py
i **
i *
Here is SQLAlchemy query snippet.
filter(User.name != None)
after autopep8, this code will like this
filter(User.name is not None)
and this query cannot works.
Hi,
all test_w602_* fail with python3 in 0.5.1 and current HEAD:
* Testing of dev-python/autopep8-0.5.1 with CPython 3.2... ..........................................................Traceback (most recent call last): File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 688, in sys.exit(main()) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 684, in main fix_file(args[0], opts) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 629, in fix_file fixed_source = fix.fix() File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 162, in fix self._fix_source() File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 137, in _fix_source modified_lines = fix(result) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 484, in fix_w602 ast_body = ast.parse(line[indent_offset:]).body[0] File "/usr/lib64/python3.2/ast.py", line 36, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 1 raise ValueError, "info", traceback ^ SyntaxError: invalid syntax FTraceback (most recent call last): File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 688, in sys.exit(main()) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 684, in main fix_file(args[0], opts) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 629, in fix_file fixed_source = fix.fix() File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 162, in fix self._fix_source() File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 137, in _fix_source modified_lines = fix(result) File "/var/tmp/portage/dev-python/autopep8-0.5.1/work/autopep8-0.5.1/autopep8.py", line 484, in fix_w602 ast_body = ast.parse(line[indent_offset:]).body[0] File "/usr/lib64/python3.2/ast.py", line 36, in parse return compile(source, filename, mode, PyCF_ONLY_AST) File "", line 1 raise ValueError, "info", traceback # comment ^ SyntaxError: invalid syntax F........test/test_autopep8.py:544: DeprecationWarning: Please use assertEqual instead. self.assertEquals(f.read(), fixed) ......... ====================================================================== FAIL: test_w602_raise_argument_triple (__main__.TestFixPEP8Warning) ---------------------------------------------------------------------- Traceback (most recent call last): File "test/test_autopep8.py", line 455, in test_w602_raise_argument_triple self.assertEqual(self.result, fixed) AssertionError: '' != 'raise ValueError("info"), None, traceback\n' + raise ValueError("info"), None, traceback ====================================================================== FAIL: test_w602_raise_argument_triple_with_comment (__main__.TestFixPEP8Warning) ---------------------------------------------------------------------- Traceback (most recent call last): File "test/test_autopep8.py", line 461, in test_w602_raise_argument_triple_with_comment self.assertEqual(self.result, fixed) AssertionError: '' != 'raise ValueError("info"), None, traceback # comment\n' + raise ValueError("info"), None, traceback # comment
The _shorten_line logic does not work for function calls which are longer than max_line_length. Maybe a little tweaking of the algo might help.
Test file:
test.py
if spam == None:
pass
autopep8 -vi test.py
[file:test.py]
'fix_e711' is not defined.
test.py:2:9:E711 comparison to None should be 'if cond is None:'
'fix_e711' is not defined.
test.py:2:9:E711 comparison to None should be 'if cond is None:'
Is the fix_e711
missing purposely? If so, should I write a patch to add it?
autopep8-0.8.3 introduced test_fix_file() test, which requires test/example.py file, which is absent in autopep8-0.8.3.tar.gz available on PyPI.
$ python test/test_autopep8.py
..............................................................................................................................................................................................................E..................
======================================================================
ERROR: test_fix_file (__main__.TestUtils)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_autopep8.py", line 229, in test_fix_file
filename=os.path.join(ROOT_DIR, 'test', 'example.py')))
File "/tmp/autopep8-0.8.3/autopep8.py", line 1694, in fix_file
tmp_source = normalize_line_endings(read_from_filename(filename))
File "/tmp/autopep8-0.8.3/autopep8.py", line 104, in read_from_filename
encoding=detect_encoding(filename)) as input_file:
File "/tmp/autopep8-0.8.3/autopep8.py", line 77, in detect_encoding
with open(filename, 'rb') as input_file:
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/autopep8-0.8.3/test/example.py'
----------------------------------------------------------------------
Ran 225 tests in 13.518s
FAILED (errors=1)
It would be great to run autopep8 from setup test
.
So far I was able to add autopep8 by addng this to setup.py
:
tests_require=['autopep8'],
Currently running it will download autopep8 egg locally but I don't know how to make it run by default.
There are many cases that break fix_e111(). I wonder if we should just take the "Reindenter" class from
http://svn.python.org/projects/python/trunk/Tools/scripts/reindent.py
It works well. And it is under public domain. What do you think?
autopep8{* e702}]$ git diff master
diff --git a/autopep8.py b/autopep8.py
index 9294ecd..d528fda 100755
--- a/autopep8.py
+++ b/autopep8.py
@@ -710,7 +710,7 @@ class FixPEP8(object):
return
offset = result['column'] - 1
- first = target[:offset].rstrip(';')
+ first = target[:offset].rstrip(';').rstrip()
second = (_get_indentation(logical_lines[0]) +
target[offset:].lstrip(';').lstrip())
diff --git a/test/test_autopep8.py b/test/test_autopep8.py
index aa80e91..7138e14 100644
--- a/test/test_autopep8.py
+++ b/test/test_autopep8.py
@@ -1344,7 +1344,7 @@ if True:
self.assertEqual(self.result, fixed)
def test_e702(self):
- line = "print 1; print 2\n"
+ line = "print 1 ; print 2\n"
fixed = "print 1\nprint 2\n"
self._inner_setup(line)
self.assertEqual(self.result, fixed)
Consider a simple .py file that just has one line of code like this:
print '**'
run autopep8 with it, the following messages will prompt:
/home/.../autopep8.py:1488: UnicodeWarning:
Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if fixed_source == tmp_source:
'ascii' codec can't decode byte 0xe4 in position 55: ordinal not in range(128)
Seems a unicode problem, then I tried:
print u'**'
but it keeps showing the same error:
/home/.../autopep8.py:1488: UnicodeWarning:
Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if fixed_source == tmp_source:
'ascii' codec can't decode byte 0xe4 in position 56: ordinal not in range(128)
This may be a serious problem since it occurs on any CJK characters (Japanese:ジャパン, Korean:한국). I didn't work out the reason, please fix it :)
Only the first parameter in a list of many, perhaps continuing for several lines, is fixed:
setup(
- name = 'sympy', version = sympy.__version__,
+ name= 'sympy', version = sympy.__version__,
description = 'Computer algebra system (CAS) in Python',
If the suggested change is made, no other change (e.g. to the space around the equal sign after version nor to the space after description) is corrected.
I launch autopep8 on a file which containt é in a comment i have this traceback (my file starts with # -- coding: utf-8 --)
/Envs/anpv/lib/python2.6/site-packages/autopep8.py:1488: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
if fixed_source == tmp_source:
'ascii' codec can't decode byte 0xc3 in position 240: ordinal not in range(128)
Regards,
autopep8 replaces the {}.has_key() form with 'in', breaks some programs with Beautiful Soup 4.
Consider this tiny program:
text = """line one
line two indented by <tab>
line three indented by <space><space>
line four"""
lines = text.split('\n')
text = '\n'.join('>' + l for l in lines)
print text
print 'length:', len(text)
When run it produces this output:
# python multiline-string.py
>line one
> line two indented by <tab>
> line three indented by <space><space>
>line four
length: 90
After running it through autopep8 0.6 the output changes to:
# python multiline-string.py
>line one
> line two indented by <tab>
> line three indented by <space><space>
>line four
length: 97
as <tab> has been changed to 8*<space>.
To be fair, pep8 is broken in that regard, too:
# pep8 multiline-string.py
multiline-string.py:2:1: W191 indentation contains tabs
multiline-string.py:3:1: E101 indentation contains mixed spaces and tabs
Suppose I have some function call that takes a lambda (or an expression with a lambda that can be spread on multiple lines):
some_func(stuff=lambda some, more, *arguments, **keywords: some_expressions and some_other_way_longer_expression)
don't fit under 80 columns.
How about if autopep8 would format it like:
some_func(
stuff=lambda some, more, *arguments, **keywords:
some_expressions and some_other_way_longer_expression
)
Currently it puts all the lambda on a single line.
$ python -c 'print("#" * 79)'; cat w79.py
###############################################################################
if condition_foo and something_long_object_name(plus, its, many, arguments, here):
pass
$ autopep8 --max-line-length=79 -vv w79.py
[file:w79.py]
---> 1 issue(s) to fix {'E501': set([1])}
---> Not fixing E501 on line 1
if condition_foo and something_long_object_name(plus, its, many, arguments, here):
pass
I am expecting output:
if condition_foo and something_long_object_name(plus, its, many, arguments,
here):
pass
By the way, really nice tool!
I tried running 'autopep8 -d' on file sphinx/sphinx/environment.py (1762 lines) and here are the timings on an imac with 2.7G core i5 and 8G ram:
real 0m6.042s
user 0m5.981s
sys 0m0.058s
I am using python 2.7.3 release (built from source).
The "ignore" function of autopep8 seems to be spotty for me. Sometimes it will ignore many instances of an error, even if I don't pass any arguments to the "ignore" parameter. Sometimes it will simply not ignore the arguments I pass at all. Below is a simple example:
mydict = {
'longkey': {
'key2': {
'longkey3': 1,
}
}
}
mydict['longkey']['key2']['longkey3'] = 'my long string goes here that goes well past line 80'
Calling pep8 on the file returns the following error:
over_80_char.py:9:80: E501 line too long (94 characters)
Running autopep8 with the following command:
autopep8 over_80_char.py --ignore=E501
Gives the following updated output:
mydict = {
'longkey': {
'key2': {
'longkey3': 1,
}
}
}
mydict['longkey']['key2']['longkey3']
= 'my long string goes here that goes well past line 80'
Note that it still attempted to compensate for E501 despite my ignore message. It also gives an invalid syntax for the updated line code, but that is another issue that I will submit separately.
autopep8 (version f682f7e) produces an AssertionError when processing an UTF8 encoded with with a byte order mark (BOM). The same file is processed just fine when the BOM is removed.
$ file foo.py foo.py: HTML document, UTF-8 Unicode (with BOM) text, with CR, LF line terminators $ autopep8 -i foo.py Traceback (most recent call last): File "/usr/local/bin/autopep8", line 9, in load_entry_point('autopep8==0.8.2', 'console_scripts', 'autopep8')() File "/usr/local/lib/python2.7/dist-packages/autopep8-0.8.2-py2.7.egg/autopep8.py", line 1828, in main fix_file(name, opts, output) File "/usr/local/lib/python2.7/dist-packages/autopep8-0.8.2-py2.7.egg/autopep8.py", line 1670, in fix_file fixed_source = fix.fix() File "/usr/local/lib/python2.7/dist-packages/autopep8-0.8.2-py2.7.egg/autopep8.py", line 234, in fix results = _execute_pep8(pep8_options, self.source) File "/usr/local/lib/python2.7/dist-packages/autopep8-0.8.2-py2.7.egg/autopep8.py", line 1054, in _execute_pep8 checker.check_all() File "/usr/local/lib/python2.7/dist-packages/pep8-1.3.3-py2.7.egg/pep8.py", line 1340, in check_all self.check_logical() File "/usr/local/lib/python2.7/dist-packages/pep8-1.3.3-py2.7.egg/pep8.py", line 1269, in check_logical self.build_tokens_line() File "/usr/local/lib/python2.7/dist-packages/pep8-1.3.3-py2.7.egg/pep8.py", line 1263, in build_tokens_line assert self.logical_line.strip() == self.logical_line AssertionError
In Python 2.6, the source code that gets written to the temporary file is corrupted. This is possibly due to some unicode issue. The current workaround is to install a recent version of pep8 to avoid spawning pep8 as a subprocess.
Note that this works fine in Python 2.7 and above.
I want to fix E72 via lib2to3's "idioms" fixer. When I run it on the command line, it works.
$ 2to3 -f idioms blah.py
type('') == type('')
becomes
isinstance('', type(''))
But I haven't yet been able to get it to work via lib2to3 yet. It doesn't raise any error. It just doesn't fix it.
Note the following example:
mydict = {
'longkey': {
'key2': {
'longkey3': 1,
}
}
}
mydict['longkey']['key2']['longkey3'] = 'my long string goes here that goes well past line 80'
For which autopep8 gives the following output:
mydict = {
'longkey': {
'key2': {
'longkey3': 1,
}
}
}
mydict['longkey']['key2']['longkey3']
= 'my long string goes here that goes well past line 80'
This is invalid syntax and should put a backslash at the end of the first part of the broken line.
autopep8 tries to convert "raise a, b, c" into "raise a(b, c)", but that's incorrect. "raise a(b), None, c" would be correct in some cases but not all (depending on the values of a and b). I don't think there's a guaranteed-safe way to make this transformation statically, so it's better to leave three-argument raise alone.
Sample code:
https://github.com/facebook/tornado/blob/master/tornado/web.py#L977
autopep8 cannot be run recursively on a directory structure
See test_e12_large()
intest_autopep8.py
. Also,
MACS-1.4.2/lib/PeakDetect.py
cement-1.9.10/tests/core/controller_tests.py
I wonder if we should do a syntax check in the E12 fixer and not commit the change if the indentation is wrong.
The following Python input makes autopep8 0.5.2/HEAD crash.
class Foo():
def __init__(self):
x= 3 # i.e. "x=<space><tab>3"
The important (and hard to see) part is the space followed by a tab. If I remove that tab the crash goes away.
The traceback is:
Traceback (most recent call last):
File "/usr/bin/autopep8-2.6", line 9, in <module>
load_entry_point('autopep8==0.5.2', 'console_scripts', 'autopep8')()
File "/usr/lib64/python2.6/site-packages/autopep8.py", line 686, in main
fix_file(args[0], opts)
File "/usr/lib64/python2.6/site-packages/autopep8.py", line 644, in fix_file
fixed_source = fix.fix()
File "/usr/lib64/python2.6/site-packages/autopep8.py", line 161, in fix
pep8result = self._execute_pep8(self.filename)
File "/usr/lib64/python2.6/site-packages/autopep8.py", line 121, in _execute_pep8
tmp_checker.check_all()
File "/usr/lib64/python2.6/site-packages/pep8.py", line 949, in check_all
for token in tokenize.generate_tokens(self.readline_check_physical):
File "/usr/lib64/python2.6/tokenize.py", line 346, in generate_tokens
("<tokenize>", lnum, pos, line))
File "<tokenize>", line 3
x = 3
^
IndentationError: unindent does not match any outer indentation level
$ python --version
Python 2.7.3
$ pep8 --version
1.3.3
$ ../autopep8/autopep8.py --version
autopep8: 0.8.1
Notice that the offered corrections are too long, extending to 89 chars.
$ ../autopep8/autopep8.py -r --select=E128,E501 --diff sympy/solvers/ode.py
@@ -3081,5 +3105,5 @@
C1 = Symbol('C1')
r = match # {'m1':m1, 'm2':m2, 'y':y}
return Eq(C.Integral(r['m2']['coeff']*r['m2'][r['y']]/r['m1'][r['y']],
- (r['y'], None, f(x))), C.Integral(-r['m1']['coeff']*r['m1'][x]/
- r['m2'][x], x)+C1)
+ (r['y'], None, f(x))), C.Integral(-r['m1']['coeff']*r['m1'][x]/
+ r['m2'][x], x)+C1)
steps to reproduce :
[xxxxx@localhost guest]# cat testpyt.py
k = "this is a super long sentence to test the character limit of defining a variable that exceeds atleast 80 characters and see if this is taken care of autopep8 and what changes it does"
print k
[xxxxx@localhost guest]# pep8 testpyt.py
testpyt.py:2:80: E501 line too long (188 > 79 characters)
[xxxxx@localhost guest]# autopep8 testpyt.py > testpyt2.py
[root@localhost guest]# pep8 testpyt2.py
testpyt2.py:2:80: E501 line too long (188 > 79 characters)
version information :
[root@localhost guest]# pep8 --version
1.3.3
[root@localhost guest]# autopep8 --version
autopep8: 0.8
Is there a possibility that autopep8 does not fix block comments (i.e. replaces #Comment with # Comment)? I have a couple of files that I want to convert to pep8 issue by issue but it seems that no matter which issue I select via --select the comments are always fixed.
i'd like to be able to run autopep8 to get the django migration files pep8 compliant, but it cant handle these files at all.
run autopep8 on this file (test.py):
#!/usr/bin/python
# -*- coding: utf-8 -*-
# Stéphane contains non-ascii char
correct = dict().has_key('good syntax ?')
$ python autopep8.py --verbose --diff /tmp/test.py [file:/tmp/test.py] 1 issues to fix 'ascii' codec can't decode byte 0xc3 in position 4: ordinal not in range(128)
If we replaces 'é' by 'e' then:
$ python autopep8.py --verbose --diff /tmp/test.py [file:/tmp/test.py] 1 issues to fix 0 issues to fix --- original//tmp/test.py +++ fixed//tmp/test.py @@ -1,4 +1,4 @@ #!/usr/bin/python # -*- coding: utf-8 -*- # Stephane contains non-ascii char -correct = dict().has_key('good syntax ?') +correct = 'good syntax ?' in dict()
From 0.6.2 to 0.6.3 the time for a file with 577 lines and 29K size has gone from 1 second to 51 seconds (with 100% CPU usage all the way).
# time autopep8 --ignore=E303,W191,E501,E101 -i foo.py # with 0.6.2
real 0m1.186s
user 0m1.138s
sys 0m0.037s
... restoring original state of foo.py here ...
# time autopep8 --ignore=E303,W191,E501,E101 -i foo.py # with 0.6.3
real 0m51.472s
user 0m51.033s
sys 0m0.063s
Both of these were using pep8 version 1.2 and Python 2.6.8 internally.
For copyright reasons I cannot share the involved file with you, sorry.
test/bad_encoding.py and test/bad_encoding2.py are missing in PyPI tarball, which results in errors in test_read_from_filename_with_bad_encoding() and test_read_from_filename_with_bad_encoding2().
$ PYTHONPATH="." python2.7 test/test_autopep8.py
.................................................................................................................................EE.
======================================================================
ERROR: test_read_from_filename_with_bad_encoding (__main__.TestUtils)
Bad encoding should not cause an exception.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_autopep8.py", line 79, in test_read_from_filename_with_bad_encoding
os.path.join(ROOT_DIR, 'test', 'bad_encoding.py')))
File "/tmp/autopep8-0.6.4/autopep8.py", line 81, in read_from_filename
encoding=detect_encoding(filename)) as input_file:
File "/tmp/autopep8-0.6.4/autopep8.py", line 59, in detect_encoding
with open(filename, 'rb') as input_file:
IOError: [Errno 2] No such file or directory: '/tmp/autopep8-0.6.4/test/bad_encoding.py'
======================================================================
ERROR: test_read_from_filename_with_bad_encoding2 (__main__.TestUtils)
Bad encoding should not cause an exception.
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/test_autopep8.py", line 84, in test_read_from_filename_with_bad_encoding2
os.path.join(ROOT_DIR, 'test', 'bad_encoding2.py')))
File "/tmp/autopep8-0.6.4/autopep8.py", line 81, in read_from_filename
encoding=detect_encoding(filename)) as input_file:
File "/tmp/autopep8-0.6.4/autopep8.py", line 59, in detect_encoding
with open(filename, 'rb') as input_file:
IOError: [Errno 2] No such file or directory: '/tmp/autopep8-0.6.4/test/bad_encoding2.py'
----------------------------------------------------------------------
Ran 132 tests in 3.852s
FAILED (errors=2)
pep8 1.3 was released yesterday. Their change log say that the internal API of pep8 1.3 is not backwards compatible to earlier releases. What I experience at runtime seems to confirm that statement:
# autopep8 --ignore=E303,W191,E501,E101 -i foo.py
:44:80: E501 line too long (109 characters)
:44:1: W191 indentation contains tabs
[..]
As you can see W191 is reported despite my request to ignore it. Did not happen with pep8 <=1.2.
The tests should verify that the pep8ized file generates the same bytecode as the original file.
There should be some sort of smart comparison because line numbers should not be compared.
I think is very important to verify that this tool doesn't actually change the code.
"Correct some non-idiomatic Python code." is mentioned in the readme but no details on what corrections are made ? This should be disabled for the bytecode match tests if it does code reductions or optimizations.
is this because there is no way to know where to split this? or you cant do it without modifying the meaning of the code?
i'm not sure if there is a way to add line continuation characters or to break up chained functions, but this is another issue i saw
I downloaded sphinx: https://bitbucket.org/birkenfeld/sphinx in order to run autopep8 on it.
nosetests
has 11 skips but no failures.autopep8 sphinx -r -v -i
(still no failures in nosetests
), but one file (sphinx/sphinx/search/ja.py
) starts with something ridiculous like 2642 E231 missing whitespace after ':'
issues.autopep8
this file repeatedly so all but E501s are fixed.nosetest
has 11 skips but 1 failure...FAIL: test_autodoc.test_generate
----------------------------------------------------------------------
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/nose/case.py", line 197, in runTest
self.test(*self.arg)
File "/home/andy/sphinx/tests/test_autodoc.py", line 447, in test_generate
assert_processes(should, 'class', 'Class')
File "/home/andy/sphinx/tests/test_autodoc.py", line 367, in assert_processes
set(items)
AssertionError
I'm afraid I don't know how to give a better test case at the moment, perhaps it is something to do with the Japanese characters... It seems to be reproducible with this file... obviously looking at this file PEP8 compliance is not so important since are not important, but nevertheless autopep8
shouldn't change the meaning of the code?
p.s. Thanks for the great tool, it usually works great!
Commit ca66005 introduces a bug:
$ autopep8 -i *.py
Traceback (most recent call last):
File "/Volumes/Raptor/Library/Python/2.7/bin/autopep8", line 8, in <module>
load_entry_point('autopep8==0.8.4', 'console_scripts', 'autopep8')()
File "/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/autopep8-0.8.4-py2.7.egg/autopep8.py", line 1906, in main
fix_file(name, opts, output)
File "/Volumes/Raptor/Library/Python/2.7/lib/python/site-packages/autopep8-0.8.4-py2.7.egg/autopep8.py", line 1767, in fix_file
fp.write(fixed_source)
TypeError: must be unicode, not str
Reverting to the previous commit (c16da22) fixes this.
[]$ ../autopep8/autopep8.py --diff --select=E71 jnk.txt
--- original/jnk.txt
+++ fixed/jnk.txt
@@ -1,4 +1,4 @@
-if x==None:
+if x is None:
pass
if x==True:
pass
[]$ cat jnk.txtif x==None:
pass
if x==True:
pass
if x == True:
pass
if x == False and 1:
pass
[]$ pep8 --version
1.3.3
[]$ ../autopep8/autopep8.py --version
autopep8: 0.8.1
[]$ python --version
Python 2.7.3
I just got a case where autopep8 produces invalid python code by inserting a single space character in a variable name.
The file on where I noticed this problem is https://github.com/geops/pg_routejoin/blob/cbaca86b3a6d37869ff1b3e3edba027f0db52e71/routejoin/table.py with the relevant line being line 46.
After reformating the file with autopep8 the line
return "%s %s on %s" % (self.jointype if self.jointype!=None else "join", self.fullname, ' and '.join(joined_columns))
gets converted to
return "%s %s on %s" % (self.jointype if self.join type != None else "join", self.fullname, ' and '.join(joined_columns))
I tried to create a simpler testcase, but could only reproduce the problem with the original file.
I used the current autopep8 version from Pypi (autopep8-0.6.tar.gz). Feel free to include the table.py file in your testcases if you want to.
make autopep8 able to detect python scripts without extension
mainly it should only check if the first line of the files without extension starts with #!
and contains python
.
Try autopep8 on this function:
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
and it suggests:
def long_function_name(
var_one, var_two, var_three,
var_four):
print(var_one)
Perhaps this is not behavior that is wanted, but I do a lot of my editing on a Windows system via SSH to a Linux box. My editor warns of mixed line endings after autopep8 parses E501 errors.
If this is a fix that you want, I will work on it, since I'd like to contribute. I find this project very useful.
test_broken.py:
0,11/2
Running autopep8 on test_broken.py results in incorrect output:
$ autopep8 test_broken.py
0, 1 1 /2
Instead I would expect:
0, 11 / 2
Here is the output of pep8 for reference:
$ pep8 test_broken.py
test_broken.py:1:2: E231 missing whitespace after ','
test_broken.py:1:5: E225 missing whitespace around operator
I was attempting to use autopep8.fix_string() to format a string and my system pep8 version is < 1.3a2. The fallback/compatibility mode attempts to open filename("") to determine encoding (line 230) which causes an exception. I worked around it by using a newer version of pep8, but thought I'd open an issue if you wanted to handle the failure more gracefully or make note of this limitation somewhere.
Example:
$ echo 'someverylongindenttionwhatnot().foo().bar().baz("and here is a long string 123456789012345678901234567890")' > test.py
$ autopep8 test.py
someverylongindenttionwhatnot().foo(
).bar().baz("and here is a long string 123456789012345678901234567890")
I'd prefer:
someverylongindenttionwhatnot().foo().bar().baz(
"and here is a long string 123456789012345678901234567890")
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.