Skip to content

Commit ffc01a0

Browse files
Fix schema generation error caused by new click version (#4750)
* Fix schema generation error caused by new click version Not sure on the policy for updating versions, so to cope with the new click 8.3.0 version I used some code from #4577 for version conditional behavior. When >= 8.3.0, unset defaults are now the special UNSET sentinal instead of None. Hopefully nothing breaks on the click._utils usage since it's an _ module, might have to find a different solution if it does. * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add ignore for mypy error * Actually fix mypy errors with ignore * Add explanation for ignores --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent 626b32f commit ffc01a0

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/generate_schema.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import json
2+
from importlib.metadata import version as imp_version
23
from typing import IO, Any
34

45
import click
6+
from packaging.version import Version
57

68
import black
79

@@ -38,6 +40,11 @@ def generate_schema_from_click(
3840
result[name]["description"] = param.help
3941

4042
if param.default is not None and not param.multiple:
43+
if Version(imp_version("click")) >= Version("8.3.0"):
44+
# Ignore the attr-defined error from running with click < 8.3.0, and
45+
# also ignore the error for unused-ignore with click >= 8.3.0
46+
if param.default is click._utils.UNSET: # type: ignore[attr-defined, unused-ignore]
47+
continue
4148
result[name]["default"] = param.default
4249

4350
return result

0 commit comments

Comments
 (0)