Skip to content

Commit

Permalink
🐛 version 1.8.17
Browse files Browse the repository at this point in the history
fix `namespace`
  • Loading branch information
RF-Tar-Railt committed Jul 4, 2024
1 parent a61de51 commit 506dbc0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# 更新日志

## Alconna 1.8.17

### 修复

- 更改 `namespace` 会覆盖先前已挂载的命名空间配置的问题

## Alconna 1.8.16

### 修复
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 @@ -51,7 +51,7 @@
from .typing import UnpackVar as UnpackVar
from .typing import Up as Up

__version__ = "1.8.16"
__version__ = "1.8.17"

# backward compatibility
AnyOne = ANY
18 changes: 14 additions & 4 deletions src/arclet/alconna/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,21 +86,31 @@ class namespace(ContextManager[Namespace]):

def __init__(self, name: Namespace | str):
"""传入新建的命名空间的名称, 或者是一个存在的命名空间配置"""
self.np = Namespace(name) if isinstance(name, str) else name
self.name = self.np.name if isinstance(name, Namespace) else name
if isinstance(name, Namespace):
self.np = name
self.name = name.name
if name.name not in config.namespaces:
config.namespaces[name.name] = name
elif name in config.namespaces:
self.np = config.namespaces[name]
self.name = name
else:
self.np = Namespace(name)
self.name = name
config.namespaces[name] = self.np
self.old = config.default_namespace
config.default_namespace = self.np

def __enter__(self) -> Namespace:
return self.np

def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type or exc_val or exc_tb:
return False
config.default_namespace = self.old
config.namespaces[self.name] = self.np
del self.old
del self.np
if exc_type or exc_val or exc_tb:
return False


class _AlconnaConfig:
Expand Down

0 comments on commit 506dbc0

Please sign in to comment.