Skip to content

Commit 52ed30e

Browse files
committed
vendor: prefixed icon names are included in the IconName type
1 parent 22ffc00 commit 52ed30e

File tree

2 files changed

+93
-68
lines changed

2 files changed

+93
-68
lines changed

chatkit/types.py

Lines changed: 71 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from datetime import datetime
44
from typing import Any, Generic, Literal
55

6-
from pydantic import AnyUrl, BaseModel, Field
6+
from pydantic import AnyUrl, BaseModel, Field, StringConstraints
77
from typing_extensions import Annotated, TypeIs, TypeVar
88

99
from chatkit.errors import ErrorCode
@@ -829,70 +829,73 @@ class EntitySource(SourceBase):
829829
FeedbackKind = Literal["positive", "negative"]
830830
"""Literal type for feedback sentiment."""
831831

832-
833-
IconName = Literal[
834-
"agent",
835-
"analytics",
836-
"atom",
837-
"batch",
838-
"bolt",
839-
"book-open",
840-
"book-closed",
841-
"book-clock",
842-
"bug",
843-
"calendar",
844-
"chart",
845-
"check",
846-
"check-circle",
847-
"check-circle-filled",
848-
"chevron-left",
849-
"chevron-right",
850-
"circle-question",
851-
"compass",
852-
"confetti",
853-
"cube",
854-
"desktop",
855-
"document",
856-
"dot",
857-
"dots-horizontal",
858-
"dots-vertical",
859-
"empty-circle",
860-
"external-link",
861-
"globe",
862-
"keys",
863-
"lab",
864-
"images",
865-
"info",
866-
"lifesaver",
867-
"lightbulb",
868-
"mail",
869-
"map-pin",
870-
"maps",
871-
"mobile",
872-
"name",
873-
"notebook",
874-
"notebook-pencil",
875-
"page-blank",
876-
"phone",
877-
"play",
878-
"plus",
879-
"profile",
880-
"profile-card",
881-
"reload",
882-
"star",
883-
"star-filled",
884-
"search",
885-
"sparkle",
886-
"sparkle-double",
887-
"square-code",
888-
"square-image",
889-
"square-text",
890-
"suitcase",
891-
"settings-slider",
892-
"user",
893-
"wreath",
894-
"write",
895-
"write-alt",
896-
"write-alt2",
897-
]
898-
"""Literal names of supported progress icons."""
832+
VendorIconName = Annotated[str, StringConstraints(pattern=r"^vendor:")]
833+
834+
IconName = (
835+
Literal[
836+
"agent",
837+
"analytics",
838+
"atom",
839+
"batch",
840+
"bolt",
841+
"book-open",
842+
"book-closed",
843+
"book-clock",
844+
"bug",
845+
"calendar",
846+
"chart",
847+
"check",
848+
"check-circle",
849+
"check-circle-filled",
850+
"chevron-left",
851+
"chevron-right",
852+
"circle-question",
853+
"compass",
854+
"confetti",
855+
"cube",
856+
"desktop",
857+
"document",
858+
"dot",
859+
"dots-horizontal",
860+
"dots-vertical",
861+
"empty-circle",
862+
"external-link",
863+
"globe",
864+
"keys",
865+
"lab",
866+
"images",
867+
"info",
868+
"lifesaver",
869+
"lightbulb",
870+
"mail",
871+
"map-pin",
872+
"maps",
873+
"mobile",
874+
"name",
875+
"notebook",
876+
"notebook-pencil",
877+
"page-blank",
878+
"phone",
879+
"play",
880+
"plus",
881+
"profile",
882+
"profile-card",
883+
"reload",
884+
"star",
885+
"star-filled",
886+
"search",
887+
"sparkle",
888+
"sparkle-double",
889+
"square-code",
890+
"square-image",
891+
"square-text",
892+
"suitcase",
893+
"settings-slider",
894+
"user",
895+
"wreath",
896+
"write",
897+
"write-alt",
898+
"write-alt2",
899+
]
900+
| VendorIconName
901+
)

tests/test_types.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
from pydantic import TypeAdapter, ValidationError
3+
4+
from chatkit.types import IconName
5+
6+
7+
def test_vendor_icon_names_are_valid():
8+
"""Icon names prefixed with `vendor:` are valid."""
9+
TypeAdapter(IconName).validate_python("vendor:icon-name")
10+
TypeAdapter(IconName).validate_python("vendor:another-icon-name")
11+
12+
13+
def test_literal_icon_names_are_valid():
14+
"""Spot check some literal icon names."""
15+
TypeAdapter(IconName).validate_python("book-open")
16+
TypeAdapter(IconName).validate_python("phone")
17+
TypeAdapter(IconName).validate_python("user")
18+
19+
20+
def test_invalid_icon_names_are_rejected():
21+
with pytest.raises(ValidationError):
22+
TypeAdapter(IconName).validate_python("invalid-icon")

0 commit comments

Comments
 (0)