[New-bugs-announce] [issue25634] Add a dedicated subclass for attribute missing errors

Jun Wang report at bugs.python.org
Mon Nov 16 04:39:59 EST 2015

New submission from Jun Wang:

See this simple example:

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

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

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


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 <report at bugs.python.org>

More information about the New-bugs-announce mailing list