You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# Try changing the type annotation of Person.preferred_operating_system from str to List[str].
3
+
# Run mypy on the code.
4
+
# It tells us different places that our code is now wrong, because we’re passing values of the wrong type.
5
+
# We probably also want to rename our field - lists are plural. Rename the field to preferred_operating_systems.
6
+
# Run mypy again.
7
+
# Fix all of the places that mypy tells you need changing. Make sure the program works as you’d expect.
8
+
9
+
# When we run mypy, we get the following errors:
10
+
# type-guided.py:42: error: Argument "preferred_operating_system" to "Person" has incompatible type "str"; expected "list[str]" [arg-type]
11
+
# type-guided.py:43: error: Argument "preferred_operating_system" to "Person" has incompatible type "str"; expected "list[str]" [arg-type]
12
+
13
+
# To solve these errors, I modified the instance to pass a list of strings instead of a single string for the preferred_operating_systems field.
14
+
# Also, In order to list all possible laptops for each person, I compared the list of preferred operating systems of each person with the operating system of each laptop.
0 commit comments