Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions scripts/generate_schema.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
from importlib.metadata import version as imp_version
from typing import IO, Any

import click
from packaging.version import Version

import black

Expand Down Expand Up @@ -38,6 +40,9 @@ def generate_schema_from_click(
result[name]["description"] = param.help

if param.default is not None and not param.multiple:
if Version(imp_version("click")) >= Version("8.3.0"):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could also do something like hasattr(click, "_utils") and hasattr(click._utils, "UNSET"), though I guess it will still need a mypy type ignore. The current code is fine with me too.

Normally I'd be concerned about breaking future users if click removes or moves the private object later, but this is just an internal script; if it breaks later we can just fix it and users won't be affected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I searched around for a while but I don't see a better way of doing it that doesn't involve a mypy ignore, so 🤷.
I like the current code since it says that whatever the problem/change is, it starts in click 8.3.0.

if param.default is click._utils.UNSET:
continue
result[name]["default"] = param.default

return result
Expand Down
Loading