@@ -91,7 +91,7 @@ Nested objects with ``optional`` attributes
9191
9292When writing Python code, it is common to encounter objects with ``optional ``
9393attributes. Accessing attributes, subscript or function calls can raise
94- ``AttributeError `` or ``IndexError `` at runtime if the value is ``None ``.
94+ ``AttributeError `` or ``TypeError `` at runtime if the value is ``None ``.
9595Several common patterns have developed to ensure these operations will
9696not raise. The goal for ``?. `` and ``?[ ] `` is to make reading and writing
9797these expressions much simpler while being predictable and doing the
@@ -185,7 +185,7 @@ significantly.
185185 def get_person_email (sensor : Sensor) -> str | None :
186186 try :
187187 return sensor.machine.line.department.engineer.emails[0 ]
188- except AttributeError , IndexError :
188+ except AttributeError , TypeError :
189189 return None
190190
191191 Another approach would be to use a ``match `` statement instead. This
@@ -687,7 +687,7 @@ If ``.b`` all of the sudden is also ``None``, it would still raise an
687687issues. As the expression output can already be ``None `` the space of
688688potential output didn't change and as such no error would appear.
689689
690- If it is the intend to catch all ``AttributeError `` and ``IndexError ``,
690+ If it is the intend to catch all ``AttributeError `` and ``TypeError ``,
691691a try-except block can be used instead.
692692
693693As the ``?. `` and ``?[ ] `` would allow developers to be more explicit in
@@ -1002,7 +1002,7 @@ try-except:
10021002 def get_person_email (sensor : Sensor) -> str | None :
10031003 try :
10041004 return sensor.machine.line.department.engineer.emails[0 ]
1005- except AttributeError , IndexError :
1005+ except AttributeError , TypeError :
10061006 return None
10071007
10081008 While this will likely work, it does not provide nearly the same level
0 commit comments