473,378 Members | 1,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Gotcha I never ran into before

I've been programming in Python for about 6 years now. One of the
features I adore the most is the very useful error messages and stack
traces that make it easy to debug. However, today I ran into a
difficult to trace bug because the stack trace was reporting the
problem in the wrong place.

class Delegator(object):
def __init__(self, obj):
self.obj = obj
def __getattr__(self, attr):
return getattr(self.obj, attr)

class SpecializedDelegator(Delegator):
def get_blah(self):
return ["Returning Blah"].upper()
blah = property(fget=get_blah)

print SpecializedDelegator("Doesn't Matter").blah

The stack trace is:
Traceback (most recent call last):
File "test.py", line 12, in ?
print SpecializedDelegator("Doesn't Matter").blah
File "test.py", line 5, in __getattr__
return getattr(self.obj, attr)
AttributeError: 'str' object has no attribute 'blah'

Which is correct, but says nothing about the real problem inside the
get_blah method. Is there a good reason that when a property's fget
function throws an AttributeError that it should fall back on
__getattr__? I would think since the attribute was explicitly defined
as a property the property function should be allowed to fully crash
and burn.

Note: This example is broken up into two classes because that is how I
discovered it. Since both classes were in separate files it added to
the agony of debugging this. Luckily I was making a small incremental
change so I could just back up and figure out what went wrong.

Thanks,
Brian
Aug 9 '07 #1
0 724

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Frank Bechmann | last post by:
Eventually most of you will not learn much from this because it's just another event in the 'default argument value gotcha' series, but because it cost me some hours yesterday to spot this 'error'...
12
by: George Jempty | last post by:
OK, wanted to make a more positive contribution to start than just plonking somebody. Here's something I've discovered using "priveleged methods" a la Douglas Crockford...
5
by: David W. Fenton | last post by:
I am posting this to the newsgroup because I wasted some time on Friday troubleshooting a problem of my own making. Other people might benefit from hearing about it. I'm working on the final...
12
by: ljh | last post by:
Has anyone else noticed that the FileSystemWatcher raises the changed event twice when a file is changed? Do you have any idea why this is the case?
0
by: Yin99 | last post by:
Do the TableAdapters have any limitations, gotcha's, or anything that may bite ya in the rear down the road? I'm looking for lessons learned and/or past experience. I'm starting a new...
3
by: vbgunz | last post by:
forgive me for my bumbling confusion. I am learning javascript and got caught up in a gotcha. this may be due to Mozillas spidermonkey or most likely to my n00b mindset on how encodeURI* and...
16
by: Hendrik van Rooyen | last post by:
I thought I would share this nasty little gotcha with the group. Consider the following code fragment: <start> print 'starting kbd thread' keyboard_thread = thread.start_new_thread(kbd_driver...
14
by: Hendrik van Rooyen | last post by:
Hi, I am surprised that it took me so long to bloody my nose on this one. It must be well known - and I would like to find out how well known. So here is a CLOSED BOOK multiple choice...
0
by: Just_a_fan | last post by:
I am so happy about this I had to tell someone and since no one at the house even knows how to spell VB, I just had to make a short post. I finally got my little program to correctly do a second...
5
by: cnb | last post by:
this recursive definition of sum thrumped me, is this some sort of gotcha or am I just braindead today? and yes i know this is easy a a for x in xs acc += x or just using the builtin. def...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.