Patches item #1706323, was opened at 2007-04-24 01:30 Message generated for change (Comment added) made by jimjjewett You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1706323&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Modules Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Yaakov Nemoy (loupgaroublond) Assigned to: Nobody/Anonymous (nobody) Summary: Updated ASTVisitor Classes Initial Comment: Ok, So this is really more of a complete rewrite than a bunch of patches, but it's just a picture of what IMHO is a saner way to do this module. I suppose I could refactor alot of it to look more like the old module, but I'm still not sure what would be better, in terms of having seperate visitors to walkers. Either way, the terminology in the original wasn't much clearer. At bare minimum though, i got postorder implemented, so this code has got to be worth something valuable... I hope.... Feedback please. ---------------------------------------------------------------------- Comment By: Jim Jewett (jimjjewett) Date: 2007-04-24 17:16 Message: Logged In: YES user_id=764593 Originator: NO > I'll take a look at #3, but I'm not quite familiar with the Py3k changes Don't worry too much -- for the most part, Py3k is just a matter of cleanup. For reasonable code, there usually isn't much difference between class Old: ... and class New(object): ... But this means that when there is a difference, it is a pain to debug. So just stick with the version that will continue to be available (inheriting from object), and backwards-compatibility will take care of itself. ---------------------------------------------------------------------- Comment By: Yaakov Nemoy (loupgaroublond) Date: 2007-04-24 17:03 Message: Logged In: YES user_id=1487908 Originator: YES That looks like a good idea. I just hammered the code out last night, and I'll try to include your changes tonight if I get a chance. I'll take a look at #3, but I'm not quite familiar with the Py3k changes as I should be. ---------------------------------------------------------------------- Comment By: Jim Jewett (jimjjewett) Date: 2007-04-24 09:53 Message: Logged In: YES user_id=764593 Originator: NO I haven't looked deeply yet, but I know some feedback quickly is often better than a long wait. I do have a few style suggestions. (1) Tests for None should generally use "is" rather than "==". (2) It helps to understand the code if it is more parallel. Seeing the meth is/is not None cases reversed on the two orders confused me about how similar they were. (3) Inheriting from object (or setting __metaclass__ = type) is probably a good habit, since old-style classes will disappear in Py3K. Normally, it doesn't matter, but debugging the difference is a pain. To make the first two concrete, here is my rewording of ASTVisitor.dispatch: From: def dispatch(self, node, *args): klass = node.__class__ meth = self._get_method_for_className(klass) if self._order == self.PREORDER: if meth != None and meth(node, *args) != self.NO_CONTINUE: self._iterate_over_defaults(node, *args) elif meth == None: self._iterate_over_others(node, *args) elif self._order == self.POSTORDER: if meth == None: self._iterate_over_others(node, *args) if meth != None: self._iterate_over_defaults(node, *args) meth(node, *args) To: def dispatch(self, node, *args): klass = node.__class__ meth = self._get_method_for_className(klass) if meth is None: self._iterate_over_others(node, *args) else: if self._order == self.POSTORDER: self._iterate_over_defaults(node, *args) meth(node, *args) elif meth(node, *args) != self.NO_CONTINUE: self._iterate_over_defaults(node, *args) else: pass # pre-order, and the method said to stop ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1706323&group_id=5470 _______________________________________________ Patches mailing list Patches@python.org http://mail.python.org/mailman/listinfo/patches