From b1d3ef1ff0c9ad381e34363fdba37b64a3af4f7a Mon Sep 17 00:00:00 2001 From: zacharyaanglin Date: Sun, 10 Mar 2019 14:18:13 -0400 Subject: [PATCH] Added dataclass example to MenuConfig --- README.md | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/README.md b/README.md index 76ca493..9ba8694 100644 --- a/README.md +++ b/README.md @@ -303,6 +303,41 @@ class MenuConfig(NamedTuple): def create_menu(config: MenuConfig): title, body, button_text, cancellable = config + # ... + + +create_menu( + MenuConfig( + title="My delicious menu", + body="A description of the various items on the menu", + button_text="Order now!" + ) +) +``` + +**Even fancier** +```python +from dataclasses import astuple, dataclass + + +@dataclass +class MenuConfig: + """A configuration for the Menu. + + Attributes: + title: The title of the Menu. + body: The body of the Menu. + button_text: The text for the button label. + cancellable: Can it be cancelled? + """ + title: str + body: str + button_text: str + cancellable: bool = False + +def create_menu(config: MenuConfig): + title, body, button_text, cancellable = astuple(config) + # ... create_menu(