[Grok-dev] Re: Grok feature or bug?

Martijn Faassen faassen at startifact.com
Tue Jan 22 09:48:56 EST 2008


Sebastian Ware wrote:
> I defined two classes "class View(grok.EditForm)" by mistake, without 
> Grok complaining. Is this a feature or a bug?

> I am thinking since Grok complains if I unassociated page templates, 
> maybe this is another thing that should be checked.

Yes, ideally it should be. It's tripped me up a few times myself.

Unfortunately the way Python works is that if two declarations of a 
class exist in a row, the later one always wins. So:

class A:
    foo = "Bar"

class A:
    foo = "Fleeb"

is actually very similar behavior to:

A = "Bar"

A = "Fleeb"

the class statement simply 'assigns' the class definition to the name A.

Since Grok only starts grokking after the module has been loaded, all 
trace of the first class definition will have been lost.

We could write something that analyzes Python code that can still find 
these errors. It'd be the additional of an entirely new feature to Grok 
though, and it would have some performance impact as well.

I imagine that a tool like pyflakes or pychecker already may warn for 
this problem, so you might want to try that out.

Regards,

Martijn



More information about the Grok-dev mailing list