google / google/yapf

Lists within list comprehensions

Open
#343 0 comments 3 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

Consider the following code, which I formatted by hand:
`````python
def save_tod(time, theta, phi, psi, file_name):
cols = [
fits.Column(name=name, format=fmt, unit=unit, array=arr)
for name, fmt, unit, arr in (('TIME', 'D', 's', time_vec),
('THETA', 'D', 'rad', theta),
('PHI', 'D', 'rad', phi),
('PSI', 'D', 'rad', psi))
]
hdu = fits.BinTableHDU.from_columns(cols)
hdu.writeto(file_name, clobber=True)
`````

Yapf formats it in the following way:
`````python
def save_tod(time, theta, phi, psi, file_name):
cols = [
fits.Column(name=name, format=fmt,
unit=unit, array=arr)
for name, fmt, unit, arr in (('TIME', 'D', 's', time_vec
), ('THETA', 'D', 'rad', theta
), ('PHI', 'D', 'rad', phi
), ('PSI', 'D', 'rad', psi))
]
hdu = fits.BinTableHDU.from_columns(cols)
hdu.writeto(file_name, clobber=True)
`````
Yapf is clearly following some logic here, though in my opinion its solution is less readable than mine. Is Yapf' behaviour intentional, or should this really be a bug? If it is intentional, is there any flag that can be set in `.style.yapf` to get something that resembles the first snippet?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.