mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-28 18:50:46 +00:00
🐛 修复 metadata
This commit is contained in:
parent
0f343a0e3c
commit
151b01120a
@ -2,7 +2,7 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Generic, Iterator, KeysView, TypeVar
|
||||
from typing import Any, Generic, ItemsView, Iterator, KeysView, TypeVar
|
||||
|
||||
import ujson as json
|
||||
|
||||
@ -32,9 +32,9 @@ class Data(dict, Generic[K, V]):
|
||||
|
||||
@property
|
||||
def data(self) -> dict[K, V]:
|
||||
if not (result := _cache.get(self._file_name, None)):
|
||||
if (result := _cache.get(self._file_name)) not in [None, {}]:
|
||||
self._dict = result
|
||||
super(Data, self).__init__(result)
|
||||
else:
|
||||
path = data_dir.joinpath(self._file_name).with_suffix('.json')
|
||||
if not path.exists():
|
||||
logger.error(
|
||||
@ -53,8 +53,8 @@ class Data(dict, Generic[K, V]):
|
||||
self._dict = {}
|
||||
super(Data, self).__init__()
|
||||
|
||||
def get(self, key: K) -> V | None:
|
||||
return self.data.get(key)
|
||||
def get(self, key: K, value: Any = None) -> V | None:
|
||||
return self.data.get(key, value)
|
||||
|
||||
def __getitem__(self, key: K) -> V:
|
||||
return self.data.__getitem__(key)
|
||||
@ -71,6 +71,9 @@ class Data(dict, Generic[K, V]):
|
||||
def keys(self) -> KeysView[K, V]:
|
||||
return self.data.keys()
|
||||
|
||||
def items(self) -> ItemsView[K, V]:
|
||||
return self.data.items()
|
||||
|
||||
|
||||
HONEY_DATA: dict[str, dict[StrOrInt, list[str | int]]] = Data('honey')
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user