[Py] [Ideas] Small suggestion regarding type errors and subscription

2024-10-14 Thread James Campbell via Discussions on Python.org
Nice so it will give an error like this now ? If so, nice! ``` TypeError: Key “name” cannot be used with “NoneType” because it’s not subscripts or ``` --- [Visit Topic](https://discuss.python.org/t/small-suggestion-regarding-type-errors-and-subscription/67898/3) or reply to this email to

[Py] [Ideas] Small suggestion regarding type errors and subscription

2024-10-14 Thread James Campbell via Discussions on Python.org
If this provides you an error message on the specific key that’s missing ``` class User: profile = None u = User() u.profile.name # AttributeError: None does not have attribute name ``` Then may I suggest that this has the same ? ``` user = { “profile”: None } user[“profile”][“name”] # Ty

[Py] [Ideas] Small suggestion regarding type errors and subscription

2024-10-15 Thread James Campbell via Discussions on Python.org
Noted, yes this was more just a QOL improvement suggestion by me as it strikes me as a useful breadcrumb that could be left to help to the developer get to the bottom of where it's come from especially when debugging bad code like this. The faster they can find where the bad code is and refact

[Py] [Ideas] Small suggestion regarding type errors and subscription

2024-10-15 Thread James Campbell via Discussions on Python.org
__getattr__ already includes the attribute name in the Exception, is there a reason that __getitem__ could not do the same ? --- [Visit Topic](https://discuss.python.org/t/small-suggestion-regarding-type-errors-and-subscription/67898/11) or reply to this email to respond. You are receivi

[Py] [Ideas] Small suggestion regarding type errors and subscription

2024-10-15 Thread James Campbell via Discussions on Python.org
Of course but there is always a big gap between the code you should write And the code you’ve been given to debug 😀 --- [Visit Topic](https://discuss.python.org/t/small-suggestion-regarding-type-errors-and-subscription/67898/9) or reply to this email to respond. You are receiving this b