mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 11:18:54 -05:00
[V3 Config] Fix async context manager bug and add test (#1308)
* Fix config bug and add test * Fix the full bug * Extra safeness
This commit is contained in:
parent
11636b16d2
commit
6678b29396
@ -31,7 +31,7 @@ class _ValueCtxManager:
|
|||||||
return self.coro.__await__()
|
return self.coro.__await__()
|
||||||
|
|
||||||
async def __aenter__(self):
|
async def __aenter__(self):
|
||||||
self.raw_value = await self
|
self.raw_value = await self
|
||||||
if not isinstance(self.raw_value, (list, dict)):
|
if not isinstance(self.raw_value, (list, dict)):
|
||||||
raise TypeError("Type of retrieved value must be mutable (i.e. "
|
raise TypeError("Type of retrieved value must be mutable (i.e. "
|
||||||
"list or dict) in order to use a config value as "
|
"list or dict) in order to use a config value as "
|
||||||
@ -171,7 +171,7 @@ class Group(Value):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def defaults(self):
|
def defaults(self):
|
||||||
return self._defaults.copy()
|
return deepcopy(self._defaults)
|
||||||
|
|
||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
def __getattr__(self, item: str) -> Union["Group", Value]:
|
def __getattr__(self, item: str) -> Union["Group", Value]:
|
||||||
@ -428,7 +428,7 @@ class Config:
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def defaults(self):
|
def defaults(self):
|
||||||
return self._defaults.copy()
|
return deepcopy(self._defaults)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_conf(cls, cog_instance, identifier: int,
|
def get_conf(cls, cog_instance, identifier: int,
|
||||||
@ -669,7 +669,7 @@ class Config:
|
|||||||
# noinspection PyTypeChecker
|
# noinspection PyTypeChecker
|
||||||
return Group(
|
return Group(
|
||||||
identifiers=(self.unique_identifier, key) + identifiers,
|
identifiers=(self.unique_identifier, key) + identifiers,
|
||||||
defaults=self._defaults.get(key, {}),
|
defaults=self.defaults.get(key, {}),
|
||||||
spawner=self.spawner,
|
spawner=self.spawner,
|
||||||
force_registration=self.force_registration
|
force_registration=self.force_registration
|
||||||
)
|
)
|
||||||
|
|||||||
@ -376,3 +376,15 @@ async def test_value_ctxmgr_immutable(config):
|
|||||||
|
|
||||||
foo = await config.foo()
|
foo = await config.foo()
|
||||||
assert foo is True
|
assert foo is True
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_ctxmgr_no_shared_default(config, member_factory):
|
||||||
|
config.register_member(foo=[])
|
||||||
|
m1 = member_factory.get()
|
||||||
|
m2 = member_factory.get()
|
||||||
|
|
||||||
|
async with config.member(m1).foo() as foo:
|
||||||
|
foo.append(1)
|
||||||
|
|
||||||
|
assert 1 not in await config.member(m2).foo()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user