At 10:36 PM 5/13/2007 -0700, Collin Winter wrote:
>2. Querying instances ::
>
>      if performs(my_elf, Thieving):
>        ...

-1 on using any function other than isinstance() for this.

Rationale: isinstance() makes the code smell of inspection more 
obvious, where another function name makes it seem like you are doing 
something harmless.  In reality, performs() testing (or any other 
kind of interface testing) using if-then is always harmful in library code.


>    The second argument to ``performs()`` may also be anything with a
>    ``__contains__()`` method, meaning the following is legal: ::
>
>      if performs(my_elf, set([Thieving, Spying, BoyScout])):
>        ...
>
>    Like ``isinstance()``, the object needs only to perform a single
>    role out of the set in order for the expression to be true.

Right, so let's just use isinstance().  Likewise, issubclass() for 
checking whether instances of a class perform a role.  (And if 
issubclass() works, then roles will also be usable by PEP 3124 
generic functions without any additional effort.)

_______________________________________________
Python-3000 mailing list
Python-3000@python.org
http://mail.python.org/mailman/listinfo/python-3000
Unsubscribe: 
http://mail.python.org/mailman/options/python-3000/archive%40mail-archive.com

Reply via email to