diff --git a/dargs/dargs.py b/dargs/dargs.py index 4ab2a96..6663c8b 100644 --- a/dargs/dargs.py +++ b/dargs/dargs.py @@ -657,18 +657,20 @@ def default(self, obj) -> Dict[str, Union[str, bool, List]]: a dict containing argument information """ if isinstance(obj, Argument): - return { + output = { "object": "Argument", "name": obj.name, "type": obj.dtype, "optional": obj.optional, - "default": obj.default, "alias": obj.alias, "doc": obj.doc, "repeat": obj.repeat, "sub_fields": obj.sub_fields, "sub_variants": obj.sub_variants, } + if obj.optional and obj.default is not _Flags.NONE: + output['default'] = obj.default + return output elif isinstance(obj, Variant): return { "object": "Variant", diff --git a/tests/test_checker.py b/tests/test_checker.py index 692cc03..a294d52 100644 --- a/tests/test_checker.py +++ b/tests/test_checker.py @@ -32,7 +32,11 @@ def test_name_type(self): ca.check({"key1": 1}) with self.assertRaises(ArgumentValueError): ca.check({"key1": 0}) - + # check any keywords + ca = Argument("kwargs", dict) + anydict = {"this": 1, "that": 2, "any": 3} + ca.check({"kwargs": anydict}) + ca.check_value(anydict) def test_sub_fields(self): ca = Argument("base", dict, [