Introducing a Safe Navigation Operator in Python

I am emphasizing a point that I and others have made many times: in Python, we need to know exactly why an exception occurs.

Yes, we often see code like:

try:
    ...
except:
    pass

…but we can fix that.

If ?. is used multiple times in a single line, it becomes a debugging nightmare. We cannot restrict users to only using ?. for optional data—they will use it simply because it’s trendy.

I see it becoming similar to the assert statement, which is almost always used in production—so much so that proposals to remove the -O and -OO optimization flags are frequently heard.

Or, removing indentation, so we could write code like this: def func(args): {print()}; def func2: {print()}, in a hieroglyphic style, etc.

1 Like