1

I've got the exactly same question as the one below which hasn't got any answer yet. My environment is the latest Python 3.8.8 + windows machine. Any idea? Thanks.

TypedDict didn't raise unexpected key error

from typing_extensions import TypedDict

class SalesSummary(TypedDict):
    sales: int


def get_sales_summary() -> SalesSummary:
    return {
        "sales": 1_000,
        "country": "UK",
        "product_codes": 1,
        "dummy" : "dummy",
    }


print(get_sales_summary())

and get the return like this

{'sales': 1000, 'country': 'UK', 'product_codes': 1, 'dummy': 'dummy'}
user9191983
  • 505
  • 1
  • 4
  • 20
  • @python_user Thanks for your comment! Then how can I detect a wrong input and return any error to reject that? – user9191983 Apr 26 '22 at 06:27
  • @python_user That's the trick!! thank you so much!!! – user9191983 Apr 26 '22 at 06:54
  • @python_user but then why does a parameter ```total=False``` exist? If it doesn't raise any error for a wrong type or format, it means nothing to create an object with the use of TypedDict though? – user9191983 Apr 26 '22 at 06:59
  • @python_user thanks for your quick turnaround! Does this probably explain what my point is? Thanks! - https://stackoverflow.com/questions/65690783/initialize-a-typeddict-and-fill-keys-values-later – user9191983 Apr 26 '22 at 07:06

0 Answers0