google / google/yapf

Only the i18n line should not be reformated, but yapf refuses to edit the entire container

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

Description

Using yapf=0.24.0
Using google style, where
```
i18n_comment=#\..*
i18n_function_call=N_, _
```
I'm trying to format this minimal example:
```python
my_list=[ "one",
_("dos"),
None,
]
```
yapf produces
```python
my_list=[ "one",
_("dos"),
None,
]
```
That is only the closing `]` has been moved. I would expect the first line to be changed to put spaces around `=`, the `None,` should be shifted more to the right, and the closing `]` should have not been moved. Because yapf should only ignore the line with the i18n function call.

changing the style to be `i18n_function_call=` fixes the issue.

My simplified non minimal issue is this code snipped.

```python
my_function("a-name",
True,
an_object('input', # Nothing international
title=_("This is important"),
content=_("Revevant text to I Agree not to move"
"and to be multi-line"),
# other comment
color = '#333'),
size= 30,
weight = 35, flag = True,

)
```
It is exaggeratedly horribly formatted on purpose, but only 2 lines are i18n function calls, the other lines should be formatted, but again the only thing that happens is the `)` moving to the right, when in general should not even move.

changing the style to be `i18n_function_call=` fixes the issue and returns

```python
my_function(
"a-name",
True,
an_object(
'input', # Nothing international
title=_("This is important"),
content=_("Revevant text to I Agree not to move"
"and to be multi-line"),
# other comment
color='#333'),
size=30,
weight=35,
flag=True,
)
```

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.