[Python-bugs-list] [ python-Bugs-672098 ] Three __contains__ implementations

SourceForge.net noreply@sourceforge.net
Tue, 21 Jan 2003 20:51:22 -0800


Bugs item #672098, was opened at 2003-01-21 14:18
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=672098&group_id=5470

Category: Python Library
Group: Not a Bug
Status: Open
Resolution: None
Priority: 5
Submitted By: Jp Calderone (kuran)
Assigned to: Nobody/Anonymous (nobody)
Summary: Three __contains__ implementations

Initial Comment:

  Several classes in the stdlib implement dict-like
interfaces, but do not provide __contains__
definitions.  This is mentioned in PEP290 as a
"contra-indication" for updating code to use "k in d".
 The attached patch adds __contains__ implementations
for these stdlib classes.  As far as I can tell, this
brings all the dict-like classes in the stdlib "up to
date", so perhaps PEP290 should be updated as well.


----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-21 20:51

Message:
Logged In: YES 
user_id=357491

The code itself looks fine, but I would suggest that instead of copying code from the methods that provide the same that you change them so that the old method calls ``__contains__`` and that ``__contains__`` now takes over as the primary method.  So instead of::

     def has_key(self, name):
         return self._attrs.has_key(name)
 
    def __contains__(self, name):
        return self._attrs.has_key(name)

do::

   def has_key(self, name):
         return self.__contains__(name)

   def __contains__(self, name):
         return self._attrs.has_key(name)


Doing it this way minimizes code duplication along with the possibility of someone changing one method and not the other.

And as for usefulness of these additions, I can't comment since I use none of the modules patched, but I see no harm in adding the functionality.  So  +0 from me on applying the patch once the above changes are done.

----------------------------------------------------------------------

Comment By: Jp Calderone (kuran)
Date: 2003-01-21 18:16

Message:
Logged In: YES 
user_id=366566

Either mozilla or sf is screwing with me.  *grumble* 
There's no way I selected bisect.py for attachment.  Proper
file now attached.


----------------------------------------------------------------------

Comment By: Brett Cannon (bcannon)
Date: 2003-01-21 16:44

Message:
Logged In: YES 
user_id=357491

The attached file has no ``__contains__`` definitions for anything.  Did you attach the correct file?

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=672098&group_id=5470