Author serhiy.storchaka
Recipients Arfrever, brett.cannon, jcea, serhiy.storchaka, zach.ware
Date 2012-12-21.09:39:24
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1356082765.34.0.104041227432.issue16694@psf.upfronthosting.co.za>
In-reply-to
Content
About length_hint():

I were mean something like (even explicit getattr() not needed):

try:
    hint = type(obj).__length_hint__
except AttributeError:
    return default
try:
    val = hint(obj)
except TypeError:
    return default
...

This is a little faster because there is only one attribute lookup instead two. This is a little safer because there is a little less chance of race when an attribute changed between two lookups (it is enough non-probably and doesn't matter).

There is type(obj) here because the C code uses _PyObject_LookupSpecial() which doesn't honor instance attributes and looks only class attributes.


About concat() and iconcat():

I think only first argument can be checked. If arguments are not concatenable then '+'/'+=' operator will raise an exception. I'm not sure. Does anyone have any thoughts about this?


About methodcaller():

Here is a catch. With this implementation you can't use `methodcaller('foo', name='spam')` or `methodcaller('foo', self='spam')` (please add tests for those cases). Here is a trick needed:

def __init__(*args, **kwargs):
    self = args[0]
    self._name = args[1]
    self._args = args[2:]
    self._kwargs = kwargs

(You can add a code for better error reporting).


I have added smaller comments on Rietveld.
History
Date User Action Args
2012-12-21 09:39:25serhiy.storchakasetrecipients: + serhiy.storchaka, brett.cannon, jcea, Arfrever, zach.ware
2012-12-21 09:39:25serhiy.storchakasetmessageid: <1356082765.34.0.104041227432.issue16694@psf.upfronthosting.co.za>
2012-12-21 09:39:25serhiy.storchakalinkissue16694 messages
2012-12-21 09:39:24serhiy.storchakacreate