Black: Vim plugin does not reverse the value of let g:black_skip_string_normalization

Created on 14 Mar 2020  路  9Comments  路  Source: psf/black

Describe the bug

Setting let g:black_skip_string_normalization = 1 does string normalization.

Setting let g:black_skip_string_normalization = 0 skips string normalization.

To Reproduce

let g:black_skip_string_normalization = 1

String normalization still being applied.

let g:black_skip_string_normalization = 0

String normalization not applied.

Expected behavior

let g:black_skip_string_normalization = 1

String normalization not being applied.

let g:black_skip_string_normalization = 0

String normalization being applied.

bug

Most helpful comment

Did you verify that it actually works if you switch the value? It doesn't work for me regardless.

I had to edit the plugin file with the following patch, because it was always casting a string to a bool, which always evaluates to True (except the empty string) :

diff --git a/plugin/black.vim b/plugin/black.vim
index 8106ea1..f26de39 100644
--- a/plugin/black.vim
+++ b/plugin/black.vim
@@ -70,7 +70,7 @@ class Flag(collections.namedtuple("FlagBase", "name, cast")):
 FLAGS = [
   Flag(name="line_length", cast=int),
   Flag(name="fast", cast=bool),
-  Flag(name="string_normalization", cast=bool),
+  Flag(name="string_normalization", cast=lambda x: not int(x)),
 ]


This was on Vim 8.0.1453.

All 9 comments

The value of g:black_skip_string_normalization should be reversed when it is fed into the string_normalization parameter because it contains inverse meaning.

Did you verify that it actually works if you switch the value? It doesn't work for me regardless.

I had to edit the plugin file with the following patch, because it was always casting a string to a bool, which always evaluates to True (except the empty string) :

diff --git a/plugin/black.vim b/plugin/black.vim
index 8106ea1..f26de39 100644
--- a/plugin/black.vim
+++ b/plugin/black.vim
@@ -70,7 +70,7 @@ class Flag(collections.namedtuple("FlagBase", "name, cast")):
 FLAGS = [
   Flag(name="line_length", cast=int),
   Flag(name="fast", cast=bool),
-  Flag(name="string_normalization", cast=bool),
+  Flag(name="string_normalization", cast=lambda x: not int(x)),
 ]


This was on Vim 8.0.1453.

To be clear, the logic was flipped like you mentioned, but it actually just always did string normalization if any value was given.

Sorry I don't remember. Looking at the code it seems to be as you wrote because vim.eval returns string so unless it is set to empty string it will always resolve to True.

It was actually broken in https://github.com/psf/black/pull/1273. Before it was just like your fix with double casting.

@EgZvor I saw the commit to your fork, can you please create a PR here as that actually fixes the problem.

For now I simply added the following to my pyproject.toml under [tool.black] (very hacky and ugly, but it works for now)
string-normalization = false

Already made. I think this project is a bit inactive.

Ah, it was not linked here so I missed it. Sorry!

There are two PRs to fix this already (https://github.com/psf/black/pull/1349 and https://github.com/psf/black/pull/1545)

Could someone please merge one of them?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

devxpy picture devxpy  路  70Comments

sfermigier picture sfermigier  路  43Comments

Kristinita picture Kristinita  路  28Comments

rollschild picture rollschild  路  35Comments

odormond picture odormond  路  21Comments