Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from typing import Literal, TypedDict
- class Td(TypedDict):
- bar: str
- foo: str
- manual_literal = Literal['bar', 'foo']
- def hello_td_str(key: str, td: Td):
- return 'Hello ' + td[key]
- def hello_td_manual(key: manual_literal, td: Td):
- return 'Hello ' + td[key]
- my_td = {'bar': 'Bar', 'foo': 'Foo'}
- print(hello_td_manual('bar', my_td))
- print(hello_td_str('foo', my_td))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement