You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 31, 2020. It is now read-only.
While working on native implementation of json module I came across few issues:
There is no way to implement Python class in JavaScript so that its constructor can take keyword arguments. It is possible for regular functions, but not that easy to figure out how to do it.
https://github.com/pybee/batavia/blob/master/batavia/core/native.js#L5 here is relevant piece of code from Batavia that wraps functions with property $pyargs set to true so that they receive an array with positional arguments and an object with keyword arguments. It is useable, but not present in documentation. Builtin functions have their $pyargs set automatically. As you can see in the code, kwargs are discarded for classes and functions without $pyargs.
IMO, at the very least, the $pyargs thing should be mentioned in documentation and there should be an option to get kwargs in class ctor.
There is no tool in place, that could check whether a function was invoked with an appropriate number of parameters etc.
In Python an error will be raised when a function is called with too few or too many arguments, or multiple values for single arguments are given. JavaScript on the other hand will gladly accept more/less arguments (than in function's signature) and has no support for named parameters. As a result I found myself writing similar code to validate arguments passed to a function. I ended up creating a more generic parameter validation function, it is not ideal, but I am linking it for reference: https://github.com/pybee/batavia/blob/master/batavia/modules/json/utils.js. Such function could be invoked "manually" or somehow "automagically" called for certain functions, possibly in getattr (https://github.com/pybee/batavia/blob/master/batavia/core/native.js#L5) (I prefer the more explicit approach).
Or perhaps there is a better solution, @freakboy3742 mentioned that VOC has some sort of function annotations that specify all the details about positional and named arguments and perform validation. I don't know my way around VOC so I couldn't find it, but hopefully Russell can link relevant code.
Any thoughts? Any takers?
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
While working on native implementation of
json
module I came across few issues:https://github.com/pybee/batavia/blob/master/batavia/core/native.js#L5 here is relevant piece of code from Batavia that wraps functions with property
$pyargs
set to true so that they receive an array with positional arguments and an object with keyword arguments. It is useable, but not present in documentation. Builtin functions have their$pyargs
set automatically. As you can see in the code, kwargs are discarded for classes and functions without$pyargs
.IMO, at the very least, the
$pyargs
thing should be mentioned in documentation and there should be an option to get kwargs in class ctor.In Python an error will be raised when a function is called with too few or too many arguments, or multiple values for single arguments are given. JavaScript on the other hand will gladly accept more/less arguments (than in function's signature) and has no support for named parameters. As a result I found myself writing similar code to validate arguments passed to a function. I ended up creating a more generic parameter validation function, it is not ideal, but I am linking it for reference: https://github.com/pybee/batavia/blob/master/batavia/modules/json/utils.js. Such function could be invoked "manually" or somehow "automagically" called for certain functions, possibly in getattr (https://github.com/pybee/batavia/blob/master/batavia/core/native.js#L5) (I prefer the more explicit approach).
Or perhaps there is a better solution, @freakboy3742 mentioned that VOC has some sort of function annotations that specify all the details about positional and named arguments and perform validation. I don't know my way around VOC so I couldn't find it, but hopefully Russell can link relevant code.
Any thoughts? Any takers?
The text was updated successfully, but these errors were encountered: