diff options
| author | 2021-01-10 22:00:59 +0100 | |
|---|---|---|
| committer | 2021-01-10 22:00:59 +0100 | |
| commit | 9a4ad5f73cd2c42087643cb36b9e6076c24695fb (patch) | |
| tree | 71f7875ba31a51f48dce653b0da2c6c9aec29550 | |
| parent | Rename CachedParser to BatchParser and move it to its own module (diff) | |
Change the func name to wrapped for clarity
| -rw-r--r-- | bot/utils/function.py | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/bot/utils/function.py b/bot/utils/function.py index 8b8c7ba5c..037516ac4 100644 --- a/bot/utils/function.py +++ b/bot/utils/function.py @@ -76,23 +76,23 @@ def get_bound_args(func: t.Callable, args: t.Tuple, kwargs: t.Dict[str, t.Any]) return bound_args.arguments -def update_wrapper_globals(wrapper: types.FunctionType, func: types.FunctionType) -> types.FunctionType: +def update_wrapper_globals(wrapper: types.FunctionType, wrapped: types.FunctionType) -> types.FunctionType: """ - Update globals of `wrapper` with the globals from `func`. + Update globals of `wrapper` with the globals from `wrapped`. For forwardrefs in command annotations discordpy uses the __global__ attribute of the function to resolve their values, with decorators that replace the function this breaks because they have their own globals. This function creates a new function functionally identical to `wrapper`, which has the globals replaced with - a merge of `func`s globals and the `wrapper`s globals. + a merge of `wrapped`s globals and the `wrapper`s globals. - In case a global name from `func` conflicts with a name from `wrapper`'s globals, `wrapper` will win + In case a global name from `wrapped` conflicts with a name from `wrapper`'s globals, `wrapper` will win to keep it functional, but this may cause problems if the name is used as an annotation and - discord.py uses it as a converter on a parameter from `func`. + discord.py uses it as a converter on a parameter from `wrapped`. """ new_globals = wrapper.__globals__.copy() - new_globals.update((k, v) for k, v in func.__globals__.items() if k not in wrapper.__code__.co_names) + new_globals.update((k, v) for k, v in wrapped.__globals__.items() if k not in wrapper.__code__.co_names) return types.FunctionType( code=wrapper.__code__, globals=new_globals, |