beeware / batavia

A JavaScript implementation of the Python virtual machine.
http://pybee.org/batavia
Other
1.39k stars 424 forks source link

type(tuple) not working properly #822

Open dmoisset opened 5 years ago

dmoisset commented 5 years ago

Expected Behavior

type(tuple) returns an incorrect value

Current Behavior

When I try this on master, this returns the javascript function with the Tuple constructor. I expect this to return the type object.

Steps to reproduce

For reference, this is what cpython does:

>>> print(type(tuple))
<class 'type'>
>>> print(type(tuple) is type)
True

while batavia does the following

>>> print(type(tuple))
function (args, kwargs) {
  if (args.length === 0) {
    return new types.Tuple();
  }

  return new types.Tuple(args[0]);
}
>>> print(type(tuple) is type)
False

Your Environment

Testing on master, revision 71388f56778

dmoisset commented 5 years ago

I did a quick check, it seems to be related to https://github.com/beeware/batavia/blob/eb8ee7a/batavia/builtins/tuple.js#L5 : The tuple.__class__ is set, while other similar functions set the __call__ attribute instead. At least changing that seems to fix the problem