mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-12-08 08:22:19 +00:00
[commands] Require number of parameters at instantiation time
This allows it to bypass annotation evaluation for arguments that don't matter like self and context.
This commit is contained in:
@@ -1061,6 +1061,21 @@ def resolve_annotation(
|
||||
return evaluate_annotation(annotation, globalns, locals, cache)
|
||||
|
||||
|
||||
def is_inside_class(func: Callable[..., Any]) -> bool:
|
||||
# For methods defined in a class, the qualname has a dotted path
|
||||
# denoting which class it belongs to. So, e.g. for A.foo the qualname
|
||||
# would be A.foo while a global foo() would just be foo.
|
||||
#
|
||||
# Unfortuately, for nested functions this breaks. So inside an outer
|
||||
# function named outer, those two would end up having a qualname with
|
||||
# outer.<locals>.A.foo and outer.<locals>.foo
|
||||
|
||||
if func.__qualname__ == func.__name__:
|
||||
return False
|
||||
(remaining, _, _) = func.__qualname__.rpartition('.')
|
||||
return not remaining.endswith('<locals>')
|
||||
|
||||
|
||||
TimestampStyle = Literal['f', 'F', 'd', 'D', 't', 'T', 'R']
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user