Skip to content

Commit 4941720

Browse files
authored
Merge pull request zedr#1 from zacharyaanglin/master
Added dataclass example to MenuConfig
2 parents d1be3e1 + b1d3ef1 commit 4941720

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,41 @@ class MenuConfig(NamedTuple):
303303

304304
def create_menu(config: MenuConfig):
305305
title, body, button_text, cancellable = config
306+
# ...
307+
308+
309+
create_menu(
310+
MenuConfig(
311+
title="My delicious menu",
312+
body="A description of the various items on the menu",
313+
button_text="Order now!"
314+
)
315+
)
316+
```
317+
318+
**Even fancier**
319+
```python
320+
from dataclasses import astuple, dataclass
321+
322+
323+
@dataclass
324+
class MenuConfig:
325+
"""A configuration for the Menu.
326+
327+
Attributes:
328+
title: The title of the Menu.
329+
body: The body of the Menu.
330+
button_text: The text for the button label.
331+
cancellable: Can it be cancelled?
332+
"""
333+
title: str
334+
body: str
335+
button_text: str
336+
cancellable: bool = False
337+
338+
def create_menu(config: MenuConfig):
339+
title, body, button_text, cancellable = astuple(config)
340+
# ...
306341

307342

308343
create_menu(

0 commit comments

Comments
 (0)