Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: type checking hack #3162

Merged
merged 2 commits into from Oct 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 13 additions & 7 deletions src/bentoml/_internal/bento/build_config.py
Expand Up @@ -284,6 +284,12 @@ def conda_dependencies_validator(
)


if TYPE_CHECKING:
ListStr: t.TypeAlias = list[str]
else:
ListStr = list


@attr.frozen
class CondaOptions:

Expand All @@ -295,14 +301,14 @@ class CondaOptions:
environment_yml: t.Optional[str] = None
channels: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
dependencies: t.Optional[DependencyType] = attr.field(
default=None, validator=attr.validators.optional(conda_dependencies_validator)
)
pip: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)

def __attrs_post_init__(self):
Expand Down Expand Up @@ -402,7 +408,7 @@ class PythonOptions:
)
packages: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
lock_packages: t.Optional[bool] = attr.field(
default=None,
Expand All @@ -418,23 +424,23 @@ class PythonOptions:
)
trusted_host: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
find_links: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
extra_index_url: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)
pip_args: t.Optional[str] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(str)),
)
wheels: t.Optional[t.List[str]] = attr.field(
default=None,
validator=attr.validators.optional(attr.validators.instance_of(list)),
validator=attr.validators.optional(attr.validators.instance_of(ListStr)),
)

def __attrs_post_init__(self):
Expand Down