[Zope3-dev] Re: [Zope3-checkins] SVN:
Zope3/branches/tlotze/src/zope/interface/interface.py
Simplifying some idioms, coding style.
Jim Fulton
jim at zope.com
Mon Aug 22 12:39:09 EDT 2005
Benji York wrote:
> Thomas Lotze wrote:
>
>> Log message for revision 37985:
>> Simplifying some idioms, coding style.
>>
>> Changed:
>> U Zope3/branches/tlotze/src/zope/interface/interface.py
>>
>> -=-
>> Modified: Zope3/branches/tlotze/src/zope/interface/interface.py
>> ===================================================================
>> --- Zope3/branches/tlotze/src/zope/interface/interface.py
>> 2005-08-18 07:12:23 UTC (rev 37984)
>> +++ Zope3/branches/tlotze/src/zope/interface/interface.py
>> 2005-08-18 07:57:37 UTC (rev 37985)
>> @@ -33,12 +33,8 @@
>>
>> def invariant(call):
>> f_locals = sys._getframe(1).f_locals
>> - tags = f_locals.get(TAGGED_DATA)
>> - if tags is None:
>> - tags = f_locals[TAGGED_DATA] = {}
>> - invariants = tags.get('invariants')
>> - if invariants is None:
>> - invariants = tags['invariants'] = []
>> + tags = f_locals.setdefault(TAGGED_DATA, {})
>> + invariants = tags.setdefault('invariants', [])
>> invariants.append(call)
>> return _decorator_non_return
>
>
> I didn't review your entire check in (and I realize that this is on a
> branch), but the non-use of setdefault there was probably intentional to
> keep from constructing empty dicts and lists when they may not be used.
Yup, although I doubt it matters much one way or the other. This function
isn't called alot and setdefault is probably a little easier to read.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope3-dev
mailing list