-
Notifications
You must be signed in to change notification settings - Fork 858
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
null or none value #1025
Comments
This is really a Python question, not a TOML question. |
Could you be more specific? >>> a[0:a.index(-1)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'numpy.ndarray' object has no attribute 'index' |
It works for regular lists:
I don't know about numpy. |
This is not what I need. >>> a = np.random.rand(10)
>>> a
array([0.10020089, 0.60065517, 0.48733387, 0.64033642, 0.67891021,
0.87084298, 0.61960618, 0.44778654, 0.47544359, 0.11425436]) |
Guess I don't really understand what you want then. But like I said, this is a Python/numpy question, not a TOML specification issue. |
Well, make it short. What I want is that there could be a none or null value in toml which can be mapped into None in Python. This is not a Python question, but a TOML issue, because Python has None, but TMOL does not. |
Do you have a way to set the For instance, say you set left and right values this way: [config]
crop = {left = 1, right = 10} You can then make the right open-ended by not providing a value for [config]
crop = {left = 1} Or, more succinctly: [config]
crop.left = 1 It could be coded so that |
This is a workaround. It can solve my question to a certain extent, but not as good as I expected. In my opinion, parameters should be explicitly provided. Hidden default values are not good, especially when there are a lot of hidden default values. This may make users confused. In addition, in my example, if we want to set both values to be None, they we have to set: [config]
crop = {} This doesn't tell good information. If we can set [config]
crop = {left=none, right=none} it will be more obvious and much clearer. |
So what would be the difference between these four statements? crop = {}
crop = {left=none}
crop = {right=none}
crop = {left=none, right=none} If there wouldn't be any difference, surely the shortest would be the best one. |
Well, the difference is readability as what I have explained.
Oh, it is for 3D image, and the default is 5, not none! Isn't this surprising? Did you expect this answer before I tell you? In addition, when the default is 5, how do you write it if you want a none value? |
First off, TOML is not Python. But table keys are more explicit than anonymous tuples in Python, and They were right. This isn't a TOML issue. It is a Python issue, and you're looking for someone else to make logic shortcuts for you. You want explicit, so use crop.left = 5
crop.right = inf # left side is 5, right side is unbound
crop.top = -inf
crop.bottom = 5 # bottom side is 5, top side is unbound
crop.front = -inf
crop.rear = inf # no need for this, but who expected three dimensions before you moved the goal posts? In your Python code, let's say from math import inf
crop = conf.get("crop", {})
left = None if (left_val := crop.get("left", None)) == (-inf) else left_val
right = None if (right_val := crop.get("right", None)) == inf else right_val
result = a[left:right] If your users are informed of how to do this, then you just need to convert Use these tips, rely on smarter configuration logic, stop insisting that you don't have what you need, and you'll be fine. |
Thanks for your suggestion. You are right. I am indeed looking for a logic shortcut, otherwise I won't post the question here. |
Like I and others here have said before: Just omit the key/value pairs (whether parameters or anything else) for which you don't want a non-null value. [params]
denoise_wavelet = { image = "myfile.jpg", wavelet = "db2", convert2ycbcr = true }
# Other params are left at their default values (usually none) |
Then it goes back to what I have said: it's implict, not explict. If there are many hidden parameters, you can't see them and don't what they are. From your example, how can I know there are alose other parameters like 'sigma', 'wavelet_levels', 'mode', 'method', 'resscale_sigma', etc. Too many are hidden. Users even don't know their existence, not to mention to modify them. Even if they know their existence, it will be troublesome to modify them. For example, if they want to change one paramter from default to a different value, they will have to manually add a "new" key/value pairs. When they want to change it back to default, they have to totally delete it. Isn't this a bad design? And again, how can you set it to |
Well, TOML is not usable as a software documentation tool, nor is it meant to be used so. Don't expect it to replace your docstrings. Assuming you had |
First, please answer my question: how can you set it to |
Frankly, you shouldn't do that. If it's necessary, it's a signal of bad design. Any nullable parameter should have Also, I meant exactly what I wrote. If you didn't understand it, read it again. From my viewpoint, there is nothing more to add. |
Therefore, we need to delete to a parameter if we want to set it to
|
Or comment it out. When I write config templates, that's what I do. [options]
# rarely_touched_option = # Default None.
It needs to be said that TOML does not define default values. That is because default values are defined in your Python code, where your logic is. Also, in any documentation that you have for your code, the defaults ought to be specified there as well. You can do that in TOML comments, even though documentation is not TOML's job either. rarely_touched_option = options.get("rarely_touched_option", None) TOML is a configuration language at its heart. If you want to pass around data, or the explicit lack thereof, then there are formats more suited to that task. That's why JSON has |
If I understand it correctly, you agree that hidden default is not a good design. You said
I totally agree with you! We shouldn't rely on default in configuration. Therefore, whatever deleting a parameter or commenting a parameter, something like the following [options]
# rarely_touched_option = # Default None. is not as good as [options]
rarely_touched_option = none which is more explicit and does not rely on default of configuration. Do you agree? In addition, commenting out a parameter is not always better than deleting it. For example, crop = {left=1, right=-2, top=3, bottom=-4} I want to set |
There's nothing wrong with TOML Project's design decisions, but there are many cases where null values are necessary. Rust and Julia, which use TOML as a configuration file, have null ( |
I'm Julian, so I might be biased, the Julia document explains clearly the concepts even if you are Pythonic or TOMLic. |
A configuration file format, the purpose of which is to set values in applications, refusing to support setting a specific value, which is broadly used and supported, is quite an absurd situation. The various workarounds suggested are akin to refusing to support It is not the same thing. There is a difference, both semantic and functional, between not setting a value and actively setting it to an unset state. |
I have noticed that there has been a lot discussion about null of none value in toml, i.e. #30 #802 , but I have a question in my case.
In my case, users will set parameters to crop an image (top, bottom, left, right). If they don't want to crop that side, it seems that setting it to None is the best choice. To simplify the example, I will use a 1D image to illustrate it.
In the above case, if we can have a toml such as
it will allow users easily to set no crop for the right side of image. 0, -1, and inf does not work for this case. Value
10
works for this case, but that means users have to know the image size which may be different every time. This is not convenient.If
none
is not allowed in toml, is there a good way to solve my question? Appreciated.The text was updated successfully, but these errors were encountered: