detect all types of null default value (#1685)

* detect all types of null default value

* fix test

* address review comments
This commit is contained in:
pngwn 2022-07-01 19:23:02 +01:00 committed by GitHub
parent eb42fc3cf8
commit a2b84199d8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 5 deletions

View File

@ -1233,9 +1233,7 @@ class Radio(Changeable, IOComponent):
Returns:
(str): string of choice
"""
return (
y if y is not None else self.choices[0] if len(self.choices) > 0 else None
)
return y
def deserialize(self, x):
"""

View File

@ -537,7 +537,7 @@ class TestRadio(unittest.TestCase):
radio_input.get_config(),
{
"choices": ["a", "b", "c"],
"value": "a",
"value": None,
"name": "radio",
"show_label": True,
"label": "Pick Your One Input",

View File

@ -119,12 +119,22 @@
const is_input = is_dep(id, "inputs", dependencies);
const is_output = is_dep(id, "outputs", dependencies);
if (!is_input && !is_output && !props.value) acc.add(id); // default dynamic
if (!is_input && !is_output && has_no_default_value(props.value))
acc.add(id); // default dynamic
if (is_input) acc.add(id);
return acc;
}, new Set());
function has_no_default_value(value: any) {
return (
(Array.isArray(value) && value.length === 0) ||
value === "" ||
value === 0 ||
!value
);
}
let instance_map = components.reduce((acc, next) => {
acc[next.id] = next;
return acc;