New submission from Jun Wang:

See this simple example:

class A(): 
        def __init__(self, x=None): 
                self.x = x

        @property
        def t(self): 
                return self.x.t

        def __getattr__(self, name): 
                return 'default'

print(A().t)


AttributeError is raised as "'NoneType' object has no attribute 't'". Currently 
__getattr__ is called if any AttributeError is raised, so the result of a.t is 
*default*, while an AttributeError is the desired behavior.

The most intuitive solution seems to add a subclass of AttributeError, say 
AttributeMissError, which triggers __getattr__. At present, I have to do some 
tricky and ugly things to __getattribute__ to show where the AttributeError 
occurs, or it's quite hard to figure out what happened with no informative 
traceback messages.

----------
components: Interpreter Core
messages: 254722
nosy: 王珺
priority: normal
severity: normal
status: open
title: Add a dedicated subclass for attribute missing errors
type: enhancement
versions: Python 3.6

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25634>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to