]> git.madduck.net Git - etc/vim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Convert (most of the) configuration values from pyproject.toml to strings (#1466)
authorRichard Si <63936253+ichard26@users.noreply.github.com>
Mon, 1 Jun 2020 18:00:00 +0000 (14:00 -0400)
committerGitHub <noreply@github.com>
Mon, 1 Jun 2020 18:00:00 +0000 (11:00 -0700)
* Convert config values to string

We need to convert all configuration values from the pyproject.toml
file because Click already does value processing and conversion and
it only expects the exact Python type or string. Click doesn't like
the integer 1 as a boolean for example. This also means other
unsupported types like datetime.time will be rejected by Click as
a unvalid value instead of throwing an exception.

We only skip converting objects that are an instance of
collections.abc.Iterable because it's almost impossible to get back
the original iterable of a stringified iterable.

* Move where the conversion happens

Instead of converting the values in the merged 'default_map', I should
convert the values that were read from the 'pyproject.toml' file.

* Change collections.abc.Iterable to (list, dict)

I also moved where the conversion happens... again. I am rather indecisive
if you haven't noticed. It should be better as it takes place in the
parse_pyproject_toml logic where configuration modification already takes
place.

Actually when this PR was first created I had the conversion happen in that
return statement, but the target_version check was complaining about it being
a string. So I moved the conversion after that check, but then Click didn't
like the stringifed list, which led me to check whether the value was an
instance of an Iterable before turning it into a string. And... I forgot that
type checking before conversion would allow it to work before the
target_version check anyway.

src/black/__init__.py

index a7e89ccba61c11d4c041033c3189fc115436e9de..886d9c291952ba2a7080940344eadc2218dd0803 100644 (file)
@@ -281,7 +281,12 @@ def parse_pyproject_toml(path_config: str) -> Dict[str, Any]:
     """
     pyproject_toml = toml.load(path_config)
     config = pyproject_toml.get("tool", {}).get("black", {})
-    return {k.replace("--", "").replace("-", "_"): v for k, v in config.items()}
+    return {
+        k.replace("--", "").replace("-", "_"): str(v)
+        if not isinstance(v, (list, dict))
+        else v
+        for k, v in config.items()
+    }
 
 
 def read_pyproject_toml(