sync with Atlas

This commit is contained in:
Luciano Ramalho
2021-07-10 11:58:24 -03:00
parent a77e6d1e97
commit 1283115921
8 changed files with 108 additions and 70 deletions

View File

@@ -1,11 +1,11 @@
# tag::BOOKDICT[]
from typing import TypedDict, List
from typing import TypedDict
import json
class BookDict(TypedDict):
isbn: str
title: str
authors: List[str]
authors: list[str]
pagecount: int
# end::BOOKDICT[]
@@ -13,7 +13,7 @@ class BookDict(TypedDict):
AUTHOR_EL = '<AUTHOR>{}</AUTHOR>'
def to_xml(book: BookDict) -> str: # <1>
elements: List[str] = [] # <2>
elements: list[str] = [] # <2>
for key, value in book.items():
if isinstance(value, list): # <3>
elements.extend(
@@ -29,4 +29,4 @@ def to_xml(book: BookDict) -> str: # <1>
def from_json(data: str) -> BookDict:
whatever: BookDict = json.loads(data) # <1>
return whatever # <2>
# end::FROMJSON[]
# end::FROMJSON[]