Message177871
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. |
|
Date |
User |
Action |
Args |
2012-12-21 09:39:25 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, brett.cannon, jcea, Arfrever, zach.ware |
2012-12-21 09:39:25 | serhiy.storchaka | set | messageid: <1356082765.34.0.104041227432.issue16694@psf.upfronthosting.co.za> |
2012-12-21 09:39:25 | serhiy.storchaka | link | issue16694 messages |
2012-12-21 09:39:24 | serhiy.storchaka | create | |
|