I agree. It’s a question of whether this is about traversal or None
. I consider it the former and if you make it the latter it waters it down the usefulness enough I would probably be -0 on this.
There’s code in pydoc that could be nicely cleaned up if AttributeError
was caught:
And I came across that code a decade ago, which shows you how triggering it was to have to work around code like that.
Or you could default to True
instead. Or you could say you shouldn’t chain in that instance. You can’t protect people from every possible error; at some point you have to let linters and code reviews do some of the work.
If you view it more as hasattr()
than capturing AttributeError
then certainly; pretty much every binary operation has to look up it an attribute exists to determine what special method to ultimately call (e.g., Unravelling binary arithmetic operations in Python).
No, but that’s for a style guide of code review to decide. There is so much “ugly” code you can write in Python using very nice operators. You can’t protect everyone from every conceivable issue and at some point have to lean on people being consenting adults.