[Patch] foo.has_key -> in foo

Issue #738 resolved
Former user created an issue

Attached is a patch to convert all has_key calls to 'in ' calls.

!contains! is the same as has_key on dicts (and hopefully on any dict like objects!), but has_key is slower as it incurs a !dict! lookup to grab the has_key method

this was applied to all files except:

doc/build/lib/markdown.py

test/testlib/coverage.py

This was an automated conversion. FYI, incase this patch isn't applied immediately (which might require it to be redone =[ ), the conversion made a couple bogus changes that had to be fixed by hand:

sqlalchemy.util: switch OrderedProperties.has_key back to calling self._data.has_key. for consistency's sake

sqlalchemy.sql: fix ColumnCollection.contains to return util.OrderedProperties.contains(self, other) instead of 'in self' (endless loop) or the original self.has_key (could use super here but I believe going to the class directly is faster)

sqlalchemy.orm.mapper: Change: if identitykey in context.session:

Back to: if context.session.has_key(identitykey):

Session.has_key is VERY different from Session.contains! (evil?)

sqlalchemy.orm.util: make TranslatingDict.contains do the actual lookup work instead of has_key. in that code, call super contains instead of 'in' (endless loop). has_key no longer does the work, instead calls 'in self'

Comments (3)

  1. Log in to comment