From 0fc77c98bf5ea7ad2d0473bc3b70cee642db12a6 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 4 Jul 2023 21:45:36 -0700 Subject: [PATCH 1/5] Better error message for invalid exclude types Currently if this is a list, this ends up using the repr of the list as a regex. --- src/black/__init__.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/black/__init__.py b/src/black/__init__.py index 222cb3ca03d..aabf0ba61e6 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -157,6 +157,18 @@ def read_pyproject_toml( "target-version", "Config key target-version must be a list" ) + exclude = config.get("exclude") + if exclude is not None and not isinstance(exclude, str): + raise click.BadOptionUsage( + "exclude", "Config key exclude must be a string" + ) + + extend_exclude = config.get("extend_exclude") + if extend_exclude is not None and not isinstance(extend_exclude, str): + raise click.BadOptionUsage( + "extend-exclude", "Config key extend-exclude must be a string" + ) + default_map: Dict[str, Any] = {} if ctx.default_map: default_map.update(ctx.default_map) From 03722a291fc8f1023e1c322a5dcaf841c5219da3 Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 4 Jul 2023 21:47:19 -0700 Subject: [PATCH 2/5] changelog --- CHANGES.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index acb5a822674..f60403cdaaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -32,6 +32,8 @@ - `.pytest_cache`, `.ruff_cache` and `.vscode` are now excluded by default (#3691) - Fix black not honouring `pyproject.toml` settings when running `--stdin-filename` and the `pyproject.toml` found isn't in the current working directory (#3719) +- Black will now error if `exclude` and `extend-exclude` have invalid data types in + `pyproject.toml`, instead of silently doing the wrong thing. ### Packaging From 32c42f632a5c65777d78cab592327604e6043bbf Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 4 Jul 2023 21:47:29 -0700 Subject: [PATCH 3/5] lint --- src/black/__init__.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/black/__init__.py b/src/black/__init__.py index aabf0ba61e6..b6611bef84b 100644 --- a/src/black/__init__.py +++ b/src/black/__init__.py @@ -159,9 +159,7 @@ def read_pyproject_toml( exclude = config.get("exclude") if exclude is not None and not isinstance(exclude, str): - raise click.BadOptionUsage( - "exclude", "Config key exclude must be a string" - ) + raise click.BadOptionUsage("exclude", "Config key exclude must be a string") extend_exclude = config.get("extend_exclude") if extend_exclude is not None and not isinstance(extend_exclude, str): From df2c2c7c67702cae5802d6ac252350654ad00f5c Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 4 Jul 2023 21:50:35 -0700 Subject: [PATCH 4/5] what is github doing??? From 9f55e735ddbe600565e033543208689787b4b7db Mon Sep 17 00:00:00 2001 From: hauntsaninja Date: Tue, 4 Jul 2023 21:53:04 -0700 Subject: [PATCH 5/5] okay github seems to maybe work now --- CHANGES.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index f60403cdaaf..bfa021617cb 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -33,7 +33,7 @@ - Fix black not honouring `pyproject.toml` settings when running `--stdin-filename` and the `pyproject.toml` found isn't in the current working directory (#3719) - Black will now error if `exclude` and `extend-exclude` have invalid data types in - `pyproject.toml`, instead of silently doing the wrong thing. + `pyproject.toml`, instead of silently doing the wrong thing (#3764) ### Packaging