From 9d2c4ea94d77ac748baef81a342b2025503950f1 Mon Sep 17 00:00:00 2001 From: ItsDrike Date: Thu, 26 Sep 2024 23:30:17 +0200 Subject: [PATCH] Fix issue in a code example --- content/posts/python-type-checking.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/content/posts/python-type-checking.md b/content/posts/python-type-checking.md index 440b0a9..b2b520e 100644 --- a/content/posts/python-type-checking.md +++ b/content/posts/python-type-checking.md @@ -297,7 +297,7 @@ def print_items(lst: list[str]) -> None: # The type-checker knows `item` variable is a string now print(f"-> Item #{index}: {item.strip()}") -print_items([1, 2, 3]) +print_items(["hi", " hello ", "hey "]) ``` That said, in many cases, instead of using these specific collection types, you can use a less specific collection, so @@ -312,12 +312,12 @@ def print_items2(lst: Sequence[str]) -> None: # The type-checker knows `item` variable is a string now print(f"Item #{index}: {item.strip()}") -print_items([1, 2, 3]) # fine -print_items((1, 2, 3)) # nope +print_items(["a", "b", "c"]) # fine +print_items(("a", "b", "c")) # nope -print_items2([1, 2, 3]) # works -print_items2((1, 2, 3)) # works -print_items2({1, 2, 3}) # works +print_items2(["a", "b", "c"]) # works +print_items2(("a", "b", "c")) # works +print_items2({"a", "b", "c"}) # works ``` You may think that you could also just use a union like: `list[str] | set[str] | tuple[str, ...]`, however that still