mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-09 20:58:54 -05:00
[Config] Fix get_attr with awaited getters (#912)
This commit is contained in:
parent
c6762234e6
commit
248d2baa2a
@ -1,6 +1,6 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
from typing import Callable, Union, Tuple
|
from typing import Callable, Union, Tuple, Coroutine
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from copy import deepcopy
|
from copy import deepcopy
|
||||||
@ -191,7 +191,7 @@ class Group(Value):
|
|||||||
|
|
||||||
return not isinstance(default, dict)
|
return not isinstance(default, dict)
|
||||||
|
|
||||||
async def get_attr(self, item: str, default=None, resolve=True):
|
def get_attr(self, item: str, default=None, resolve=True) -> Union[Value, Coroutine]:
|
||||||
"""
|
"""
|
||||||
This is available to use as an alternative to using normal Python attribute access. It is required if you find
|
This is available to use as an alternative to using normal Python attribute access. It is required if you find
|
||||||
a need for dynamic attribute access.
|
a need for dynamic attribute access.
|
||||||
@ -214,13 +214,15 @@ class Group(Value):
|
|||||||
:param default:
|
:param default:
|
||||||
This is an optional override to the registered default for this item.
|
This is an optional override to the registered default for this item.
|
||||||
:param resolve:
|
:param resolve:
|
||||||
If this is :code:`True` this function will return a "real" data value, if :code:`False` this
|
If this is :code:`True` this function will return a coroutine that resolves to a "real" data value,
|
||||||
function will return an instance of :py:class:`Group` or :py:class:`Value` depending on the
|
if :code:`False` this function will return an instance of :py:class:`Group` or :py:class:`Value`
|
||||||
type of the "real" data value.
|
depending on the type of the "real" data value.
|
||||||
|
:rtype:
|
||||||
|
Coroutine or Value
|
||||||
"""
|
"""
|
||||||
value = getattr(self, item)
|
value = getattr(self, item)
|
||||||
if resolve:
|
if resolve:
|
||||||
return await value(default=default)
|
return value(default=default)
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user