Yapf: SPACES_BEFORE_COMMENT seems to have no effect

Created on 19 Jan 2019  Â·  9Comments  Â·  Source: google/yapf

It seems as yapf does not use the list of values for the SPACES_BEFORE_COMMENT knob properly.

$ yapf --style={spaces_before_comment=15,20} sample.py

works great moving all comments to the right with 15 columns,
Was before:

a_very_long_statement_that_extends_way_beyond # Comment
short # This is a shorter statement

Is now:

a_very_long_statement_that_extends_way_beyond               # Comment
short               # This is a shorter statement

However, the last comment is not moved to the right as you demonstrate in the help file.

Also, when using a setup.cfg, the list value is not being parsed properly by yapf - resulting in
yapf: '15,20' is not a valid setting for SPACES_BEFORE_COMMENT. error.

The setup.cfg file contents:

[yapf]
SPACES_BEFORE_COMMENT = 15,20
$ yapf --version
yapf 0.25.0

All 9 comments

Same version, same problem.

Fixed, but you may need to use quotes around the integer list:

$ yapf --style={spaces_before_comment="15,20"} sample.py

Which version is this fixed? I just updated to 0.26 and it does not work.

It was fixed right after the 0.26 release, so top-of-tree at the moment.

I installed the latest via pip install --upgrade git+https://github.com/google/yapf and the functionality still does not work. Perhaps a4d0b6ddd8d31800336da5207fddb8da5767dde1 fixed the argument parsing error, but what of the functionality?

Could you send me the command line you're using?

I put it in a valid python file.

╰─➤  cat test.py
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-

1 + 1  # Adding values
222 + 222  # More adding

longer_statement = 'longer'  # This is a longer statement
short = 'short'  # This is a shorter statement

a_very_long_statement_that_extends_beyond_the_final_column = 'looong'  # Comment
short = 'short'  # This is a shorter statement

and when I run yapf according to the documentation the output does not look similar.

╰─➤  yapf --style={spaces_before_comment="15,20"} test.py
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-

1 + 1               # Adding values
222 + 222               # More adding

longer_statement = 'longer'               # This is a longer statement
short = 'short'               # This is a shorter statement

a_very_long_statement_that_extends_beyond_the_final_column = 'looong'               # Comment
short = 'short'               # This is a shorter statement

I had to put single quotes around the --style flag:

$ yapf --style='{spaces_before_comment="15,20"}' /tmp/x.py
#!/usr/bin/env python3.7
# -*- coding: utf-8 -*-

1 + 1         # Adding values
222 + 222     # More adding

longer_statement = 'longer' # This is a longer statement
short = 'short'             # This is a shorter statement

a_very_long_statement_that_extends_beyond_the_final_column = 'looong' # Comment
short = 'short'                                                       # This is a shorter statement

Maybe it's a shell thing?

Confirmed, single quotes works from zsh. Thanks for the fix.

Was this page helpful?
0 / 5 - 0 ratings