-
Notifications
You must be signed in to change notification settings - Fork 447
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
Checking whether super
exists at runtime
#305
Comments
I'm not sure what your appetite is for this sort of change, but I'm happy to implement it myself, if you have no conceptual objection to it. |
It would be a major change to the language. Are you sure it's not already possible to do what you want to do in a reasonable way? |
The original idea was to produce a runtime error if I would not say this is a mission-critical blocker, so we can close the issue if you want, but it actually is high-value for our scenario. To put it in non-theoretical terms, consider if you want to tag a base class with some type tag, and then dynamically check that you're |
Let me give you a non-theoretical example. In Kubernetes, there is a concept of some entities having an optional name and labels. It is thus convenient to do something like: metadata.Name("objectNameHere") + metadata.Labels({ app: "fancyAppLabel" }) In the case of It is obviously possible to work around this, but in my estimation, it is hard to do without cluttering up the API, and when you have a lot of functions like this, I would greatly prefer to handle these transparently, to avoid user error. |
You used to be be able to do I ran into a similar problem to what you describe and worked around it by always deriving from a base object, like:
Base would always have |
Ok, so it sounds like having |
You can write it yourself:
This could also be generalized to take a secondary object instead of a single field: val pair. |
My understanding is that this will not work with {foo: "bar"} + {
f: extend_or_set(super, "foo", "baz"),
} |
Fixed by #318 |
I would like to customize behavior of some object template based on whether
super
exists, e.g., something like:A quick perusal through the spec seems to indicate that only expressions of the form
super.id
andsuper[expr]
are part of the syntax, and cursory investigation of the source does not reveal a promising direction to go in.Is doing something like this possible at all? Or perhaps this is extremely un-Jsonnet-y?
The text was updated successfully, but these errors were encountered: