yapf
yapf copied to clipboard
error formatting dict when there is a very long list
When formatting a dict with a very long value, such as a list. The following case is expected.
{
1: 1,
2: 2,
3: 3,
4:
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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, 44, 45, 46, 47, 48, 49, 50, 51]
}
But if the last list of key 4
has 52 elements, it becomes
{
1:
1,
2:
2,
3:
3,
4: [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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, 44, 45, 46, 47, 48, 49, 50,
51, 52
]
}
Similar problem occurs when
{
1:
1,
2:
2,
3:
3,
4: [
1,
1,
1,
1,
1,
1,
# omit 100 times 1s
1,
1,
1,
1,
1,
]
}
encounted at yapf 0.32.0 on linux (Amazon Linux 2 AMI)
Looks like a feature? Do I have a way to aviod this situation?
Hi there, I would love to work on it . I am new as a contributor. please let me know what to do .
As I tried both the codes , they are running .
if you are facing issue try writing the code like this.
{ 1:1, 2:2, 3:3, 4: [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 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, 44, 45, 46, 47, 48, 49, 50, 51, 52 ] }
I am bothering by the \n added at the end of the first keys
1: # I dont want to change line here.
1,
2: # I dont want to change line here.
2,
3: # I dont want to change line here.
3,
thanks for loonking into it.
Hello there, can you please let me see the code .
What do you mean by the code? the code in real life production is similar with the example I given.