Skip to content

Commit 45dfbb8

Browse files
committed
update
1 parent 991a396 commit 45dfbb8

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

Changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# 0.1.4
2+
3+
+ 修复了`boolean`型参数必须使用命令行设置无效的问题
4+
15
# 0.1.3
26

37
## bug修复

schema_entry/entrypoint.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,11 +252,12 @@ def _parse_commandline_args_by_schema(self,
252252
try:
253253
if self.schema is not None and self.schema.get("properties") is not None:
254254
if self.schema["properties"].get(key) is not None and self.schema["properties"][key]["type"] == "boolean":
255-
if self.schema.get("required") is None:
256-
value = None
257-
else:
258-
if key not in self.schema["required"]:
255+
if value is False:
256+
if self.schema.get("required") is None:
259257
value = None
258+
else:
259+
if key not in self.schema["required"]:
260+
value = None
260261
except Exception as e:
261262
warnings.warn(str(e))
262263
finally:

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = schema_entry
3-
version = 0.1.3
3+
version = 0.1.4
44
url = https://github.com/Python-Tools/schema_entry
55
author = hsz
66
author_email = hsz1273327@gmail.com

tests/test_entrypoint_without_subclass.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,32 @@ def test_load_not_required_boolean_cmd_config3(self) -> None:
386386
"b_b": "1234"
387387
})
388388

389+
def test_load_not_required_boolean_cmd_config4(self) -> None:
390+
root = EntryPoint(
391+
name="test_a",
392+
schema={
393+
"$schema": "http://json-schema.org/draft-07/schema#",
394+
"type": "object",
395+
"properties": {
396+
"a_a": {
397+
"type": "boolean",
398+
"default": False
399+
},
400+
"b_b": {
401+
"type": "string",
402+
"default": "1234"
403+
}
404+
},
405+
"required": ["a_a"]
406+
},
407+
main=lambda a_a, b_b: None
408+
)
409+
root(["--a-a"])
410+
self.assertDictEqual(root.config, {
411+
"a_a": True,
412+
"b_b": "1234"
413+
})
414+
389415
def test_load_cmd_noflag_config(self) -> None:
390416
root = EntryPoint(
391417
name="test_a",

0 commit comments

Comments
 (0)