batavia
batavia copied to clipboard
Callables do not enforce required parameters
For example:
def foo(a):
print(a)
foo()
results in (traceback from Chrome):
Traceback (most recent call last):
File "/var/folders/jy/_hlv4sxd78nd0dlxq4p4zmxr0000gn/T/tmpbu2tr58w", line 3, in <module>
File "/var/folders/jy/_hlv4sxd78nd0dlxq4p4zmxr0000gn/T/tmpbu2tr58w", line 2, in foo
NameError: local variable 'a' referenced before assignment
whereas correct Py behavior is:
>>> def foo(a):
... print(a)
...
>>> foo()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: foo() missing 1 required positional argument: 'a'
I'd like to give this one a try.
I guess this could be done this way:
- functions should be compiled as JS closures containing a list of *argnames
- on call, assert js!arguments.length == len(argnames)
- if it fails because missing arguments, use the actual *argnames tuple to index/slice the missing required arguments, produce the correct error.
- if it fails because too many arguments, complain that "$functionname takes exactly n arguments (m>n given)"
@tysonclugg started on this one yesterday. I'm de-dibbing it.