Skip to content

Commit

Permalink
feat: add strict model
Browse files Browse the repository at this point in the history
  • Loading branch information
tlambert03 committed Jun 29, 2022
1 parent fb85496 commit 73908f1
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/app_model/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ class KeybindingRuleDict(TypedDict, total=False):
# ------------------ commands-related types --------------------


class Icon(BaseModel):
class _StrictModel(BaseModel):
class Config:
extra = "forbid"


class Icon(_StrictModel):
"""Icons used to represent commands, or submenus.
May provide both a light and dark variant. If only one is provided, it is used
Expand Down Expand Up @@ -87,7 +92,7 @@ def validate(cls, v: Any) -> Icon:
return cls(**v)


class CommandRule(BaseModel):
class CommandRule(_StrictModel):
"""Data representing a command and its presentation.
Presentation of contributed commands depends on the containing menu. The Command
Expand Down Expand Up @@ -132,7 +137,7 @@ class CommandRule(BaseModel):
# ------------------ keybinding-related types --------------------


class KeybindingRule(BaseModel):
class KeybindingRule(_StrictModel):
"""Data representing a keybinding and when it should be active.
This model lacks a corresponding command. That gets linked up elsewhere,
Expand Down Expand Up @@ -174,7 +179,7 @@ def _bind_to_current_platform(self) -> Optional[KeyCodeStr]:
# ------------------ menus-related types --------------------


class _MenuItemBase(BaseModel):
class _MenuItemBase(_StrictModel):
"""Data representing where and when a menu item should be shown."""

when: Optional[context.Expr] = Field(
Expand Down

0 comments on commit 73908f1

Please sign in to comment.