Farm Development

2 stupid things I coded this week

#1


try:
    do_stuff()
except:
    etype, val, tb = sys.exc_info()
    raise etype, "%s (%s)" % (val, "happened in the context of X"), tb

#2


class UsedToBeADict(object):
    foobar = make_foobar('with sugar'),
    bazbar = 1
    fezbar = 2

If you don't see the mistakes already, here are some hints...

  • Re: 2 stupid things I coded this week

    #1:

    You are only passing two arguments to it, the etype is SQLError, so you are only passing in two arguments, the string and the traceback.

    #2:

    Comma after make_foobar(), <-- oops, tuple!

  • Re: 2 stupid things I coded this week

    Hehe cool, I've seen both of the errors - But I have to admit, I've just read about the #2 in the doc a few days ago ;-)

  • Re: 2 stupid things I coded this week

    hehe. yes, both were head scratchers, but #2 probably only because I'd been coding without a break for too long ;) The #1 is very dangerous and I can't believe I ever thought it was a good idea. The traceback basically tells you the wrong thing, heh, since you lose the context were etype is re-raised. I've slapped my own wrists for this and now am always doing:

    raise NewException("%s: %s (in context of X) % (etype.__name__, val)), None, tb

  • Re: 2 stupid things I coded this week

    I've *coded* error #2 -- and recently, too. Kind of embarassing once I realized what I'd done. :-)

    P.S. At the "Are you human?" question, I tried to answer "Only after I've had my morning caffeine", just to see what the software would do. Was kind of disappointed when it only let me type 3 letters. :-)

  • Re: 2 stupid things I coded this week

    ha! ok, I'll change that. So far it's fooled the spam bots (knock on wood).

    I really hate getting a squiggly captcha that's impossible to read, then hitting submit and getting bounced back to the start by some incompetent web form. sigh, Internet.

    Can I gripe for a minute about how americanexpress.com doesn't work in Safari or Firefox? I get a popup everytime about how they don't have my correct email but it's broken and won't let me enter in the new one! grrrr.

  • Re: 2 stupid things I coded this week

    I cant find the post at the moment, but I saw a great writeup on non-captcha solutions. The best I have found in practice is also the simplest.

    Have an input inside two div's (important).

    The top level div has a class, the inner has an id. [div class="foo"] [div id=bar] [input name="random value"/] [/div][/div]

    Then add the css: .foo #bar { display: none }

    If you see any data in that field, it's a bot.

    This keeps your form clean, and 99% of the bots out.

    The class/id trick is done because some bots do some simple CSS checks (usually first order) to see if the element is really hidden. You can also add some javascript, but that will break for clients who have JS turned off.

  • Re: 2 stupid things I coded this week

    Robin:

    > I've *coded* error #2 -- and recently, too. Kind

    > of embarassing once I realized what I'd done. :-)

    Not at all. I made it too a number of times, and certainly don't blame myself for it.

    The fact that a small, practically invisible comma, without parentheses, is enough to define a tuple is a mistake, in my opinion. I would gladly change it in Python 3.0, but our BDFL does not think so. :-|

Note: HTML tags will be stripped. Hit enter twice for a new paragraph.

Recent Projects

  • JSTestNet

    Like botnet but for JS tests in CI.

  • Nose Nicedots

    Nose plugin that prints nicer dots.

  • Fudge

    Mock objects for testing.

  • Fixture

    Loading and referencing test data.

  • NoseJS

    Nose plugin that runs JavaScript tests for a Python project.

  • Wikir

    converts reST to various Wiki formats.