Skip to content

Commit

Permalink
🐛 version 1.8.28
Browse files Browse the repository at this point in the history
  • Loading branch information
RF-Tar-Railt committed Aug 17, 2024
1 parent aeae5d2 commit 75196c3
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## 1.8.28

### 修复

- 修复 Args 上所有参数都没有默认值时, `default` 仍然被设置的问题

## 1.8.27

### 改进
Expand Down
2 changes: 1 addition & 1 deletion src/arclet/alconna/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from .typing import Up as Up
from .typing import StrMulti as StrMulti

__version__ = "1.8.27"
__version__ = "1.8.28"

# backward compatibility
AnyOne = ANY
7 changes: 4 additions & 3 deletions src/arclet/alconna/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ def __init__(
if default is not Empty and not self.default.args:
self.default.args = {self.args.argument[0].name: self.default.value} if not isinstance(self.default.value, dict) else self.default.value
self.default.value = ...
if self.default is Empty:
self.default = OptionResult(args={arg.name: arg.field.default for arg in self.args.argument if arg.field.default is not Empty})
if self.default is Empty and (defaults := {arg.name: arg.field.default for arg in self.args.argument if arg.field.default is not Empty}):
self.default = OptionResult(args=defaults)
if self.separators == ("",):
self.compact = True
self.separators = (" ",)
Expand Down Expand Up @@ -307,8 +307,9 @@ def __init__(
)
if not self.args.empty and default is not Empty and not self.default.args:
self.default.args = {self.args.argument[0].name: self.default.value} if not isinstance(self.default.value, dict) else self.default.value
self.default.args.update()
self.default.value = ...
if self.default is Empty and (defaults := {arg.name: arg.field.default for arg in self.args.argument if arg.field.default is not Empty}):
self.default = SubcommandResult(args=defaults)
self._hash = self._calc_hash()

def __add__(self, other: Option | Args | Arg | str) -> Self:
Expand Down
4 changes: 4 additions & 0 deletions tests/core_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,11 +939,15 @@ def test_default():
alc25_3 = Alconna(
"core25_3",
Option("bar", Args["baz;?", int, 321]["qux", float, 1.0]),
Option("bar1", Args["baz1;?", int]["qux1", float]),
)
res8 = alc25_3.parse("core25_3")
assert res8.query("bar.baz") == 321
assert res8.query("bar.qux") == 1.0

assert not res8.query("bar1")
assert not res8.query("bar1.baz")


def test_conflict():
core26 = Alconna(
Expand Down

0 comments on commit 75196c3

Please sign in to comment.