ironm73 / pyv8

Automatically exported from code.google.com/p/pyv8
0 stars 0 forks source link

JSArray booleaness #136

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

calling bool(x) on an empty _PyV8.JSArray object returns True.

What is the expected output? What do you see instead?

I expect it to return False, just like the python list, e.g.

assert bool([]) is False

What version of the product are you using? On what operating system?

latest, windows 7

It's probably enough to implement the __nonzero__ method for JSArray.

Original issue reported on code.google.com by nitrogen...@gmail.com on 18 Sep 2012 at 5:39

GoogleCodeExporter commented 8 years ago

Original comment by flier...@gmail.com on 18 Sep 2012 at 12:50

GoogleCodeExporter commented 8 years ago
I can't reproduce your issue, because Python will call __len__() when you use 
bool() on an object which haven't provide __nonzero__ function.

object.__nonzero__(self) 
Called to implement truth value testing and the built-in operation bool(); 
should return False or True, or their integer equivalents 0 or 1. When this 
method is not defined, __len__() is called, if it is defined, and the object is 
considered true if its result is nonzero. If a class defines neither __len__() 
nor __nonzero__(), all its instances are considered true.

could you provide your sample code? Thanks

import PyV8

assert not bool([])

with PyV8.JSContext() as ctxt:
    assert not bool(PyV8.JSArray([]))

Original comment by flier...@gmail.com on 18 Sep 2012 at 1:21