Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog/1411.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve error messaging when a command parameter's annotation cannot be resolved at runtime.
11 changes: 10 additions & 1 deletion disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,16 @@ def callback(self, function: CommandCallback[CogT, Any, P, T]) -> None:
except AttributeError:
globalns = {}

params = get_signature_parameters(function, globalns, skip_standard_params=True)
try:
params = get_signature_parameters(function, globalns, skip_standard_params=True)
except NameError as e:
msg = (
str(e)
+ ", please check all annotations are defined outside of TYPE_CHECKING blocks."
)
# todo: add name kw only argument once we use py310+
raise NameError(msg) from None

for param in params.values():
if param.annotation is Greedy:
msg = "Unparameterized Greedy[...] is disallowed in signature."
Expand Down
20 changes: 18 additions & 2 deletions disnake/ext/commands/slash_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,15 @@ def __init__(
)

if options is None:
options = expand_params(self)
try:
options = expand_params(self)
except NameError as e:
msg = (
str(e)
+ ", please check all annotations are defined outside of TYPE_CHECKING blocks."
)
# todo: add name kw only argument once we use py310+
raise NameError(msg) from None

self.docstring = utils.parse_docstring(func)
desc_loc = Localized._cast(description, False)
Expand Down Expand Up @@ -473,7 +481,15 @@ def __init__(
)

if options is None:
options = expand_params(self)
try:
options = expand_params(self)
except NameError as e:
msg = (
str(e)
+ ", please check all annotations are defined outside of TYPE_CHECKING blocks."
)
# todo: add name kw only argument once we use py310+
raise NameError(msg) from None

self.docstring = utils.parse_docstring(func)
desc_loc = Localized._cast(description, False)
Expand Down