-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add jsonnet stubs #14253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Add jsonnet stubs #14253
Conversation
This comment has been minimized.
This comment has been minimized.
stubs/jsonnet/_jsonnet/__init__.pyi
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be changed into a single top-level stub file: _jsonnet/__init__.pyi
-> _jsonnet.pyi
stubs/jsonnet/_jsonnet/__init__.pyi
Outdated
ext_vars: dict[str, str] | None = None, | ||
ext_codes: dict[str, str] | None = None, | ||
tla_var: dict[str, str] | None = None, | ||
tla_codes: dict[str, str] | None = None, | ||
max_trace: int = 20, | ||
import_callback: Callable[[str, str], tuple[str, object | None]] | None = None, | ||
native_callbacks: dict[str, tuple[tuple[str, ...], Callable[..., object]]] | None = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like None
isn't a valid argument for at least some of these. To indicate that a parameter is optional without specifying a default value, you can use parameter: annotation = ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, import_callback
and the numeric args cannot be none.
For jpathdir
, it gets type validated by calling Py(Unicode|String|List)_Check()
, so passing None
does work and is the same as not passing anything (in C the type is Py_None
vs NULL
respectively).
The dict args get passed to PyDict_Next
which returns 0 immediately if the op
argument is not of type dict
.
This works without any surprises:
>>> _jsonnet.evaluate_snippet('', '{}', ext_vars=None, ext_codes=None, tla_vars=None, tla_codes=None, jpathdir=None, native_callbacks=None)
'{ }\n'
Values that are supposed to be callables are always checked:
>>> _jsonnet.evaluate_snippet('', '{}', ext_codes=None, tla_vars=None, native_callbacks={'s': ((), None)})
Traceback (most recent call last):
File "<python-input-17>", line 1, in <module>
_jsonnet.evaluate_snippet('', '{}', ext_codes=None, tla_vars=None, native_callbacks={'s': ((), None)})
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: native callback must be callable
>>> _jsonnet.evaluate_snippet('', '{}', ext_codes=None, tla_vars=None, import_callback=None)
Traceback (most recent call last):
File "<python-input-14>", line 1, in <module>
_jsonnet.evaluate_snippet('', '{}', ext_codes=None, tla_vars=None, import_callback=None)
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: import_callback must be callable
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉 |
Python API
_jsonnet.c
I used discrete types rather than abstract. Tuple is strictly required but I do not know if
PyDict_*
API can acceptMapping
. I assume no so it's left asdict
here. Same forlist
vsCollection
when using thePyList_*
API.