labrad / pylabrad

python interface for labrad
50 stars 31 forks source link

backwards iterable-ness #351

Open pomalley opened 6 years ago

pomalley commented 6 years ago
import collections
isinstance([1,2,3]*ns, collections.Iterable)  # False
isinstance(1*ns, collections.Iterable)  # True

This seems backwards.

zchen088 commented 6 years ago

Interestingly...

In [16]: np.iterable(1*ns)
Out[16]: 0

In [17]: np.iterable([1, 2, 3]*ns)
Out[17]: 1
ejeffrey commented 6 years ago

huh.

So collections.Iterable tests for the presence of the iter method.

Value and friends have an iter method that raises a TypeError.

I don't know why. My guess is that if you don't implement iter, then under some circumstance python and/or numpy will try to iterate by calling getitem, which will do something stupid on a Value object.

On Wed, Feb 7, 2018 at 11:06 AM, Zijun Chen notifications@github.com wrote:

Interestingly...

In [16]: np.iterable(1*ns) Out[16]: 0

In [17]: np.iterable([1, 2, 3]*ns) Out[17]: 1

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/labrad/pylabrad/issues/351#issuecomment-363875889, or mute the thread https://github.com/notifications/unsubscribe-auth/ABnKHPmRfkpP5Mar6LkGL9Ix1fhgXcCaks5tSfRMgaJpZM4R9N5Y .