logoalt Hacker News

wdroztoday at 8:38 AM3 repliesview on HN

In the improved error message [0] how are they able to tell nested attributes without having a big impact in performance? Or maybe this has a big impact on performance, then using exceptions for control flow is deprecated?

    ...
    print(container.area)
> AttributeError: 'Container' object has no attribute 'area'. Did you mean: 'inner.area'?

[0] -- https://docs.python.org/3.15/whatsnew/3.15.html#improved-err...


Replies

edflsafoiewqtoday at 9:10 AM

Here's the relevant diff: https://github.com/python/cpython/pull/137968/files#diff-966...

Search is limited to 20 attributes and non-descriptors only to avoid arbitrary code execution.

I assume constructing AttributeErrors isn't highly performance sensitive.

dotancohentoday at 12:21 PM

  > using exceptions for control flow is deprecated?
Exceptions are for the exceptional cases - the ones that mean normal operations are being suspended and error messages are being generated. Don't use them for control flow.
show 2 replies
IshKebabtoday at 9:08 AM

Using exceptions for flow control has always been a bad idea, despite what they might have said. Perhaps they are generating that message lazily though?

On the other hand it's not like Python really cares about performance....

show 2 replies