ShardedQueryShardId should have __len__

Issue #2039 resolved
Former user created an issue

I can't run len(query), so I have to do:

total = 0
for i in query:
    total += 1

Which is silly. Otherwise I'm getting:

TypeError: object of type 'ShardedQueryShardId' has no len()

Comments (1)

  1. Mike Bayer repo owner

    you'd call count(), but with sharding its more complicated than that, you'd have to call count() on all your shard ids. Aggregates are exactly the thing you lose when you shard.

    Also len() not an option:

    class Iterates(object):
        def __len__(self):
            print "LEN!"
            return 5
    
        def __iter__(self):
            print "ITER!"
            return iter([2, 3, 4, 5](1,))
    
    list(Iterates())
    

    output:

    ITER!
    LEN!
    
  2. Log in to comment