sync with Atlas
This commit is contained in:
@@ -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[]
|
||||
|
||||
Reference in New Issue
Block a user