Skip to content
Open
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's annotation is stringified.
9 changes: 8 additions & 1 deletion disnake/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,14 @@ 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:
raise NameError(
"Stringified params annotations must have their reference imported outside of a TYPE_CHECKING block: "
+ e.args[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
+ e.args[0]
+ str(e)

) from None

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

if options is None:
options = expand_params(self)
try:
options = expand_params(self)
except NameError as e:
raise NameError(
"Could not expand parameters. Please check all annotations are imported outside of TYPE_CHECKING blocks. "
+ e.args[0]
Comment on lines +313 to +314
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Could not expand parameters. Please check all annotations are imported outside of TYPE_CHECKING blocks. "
+ e.args[0]
"Could not expand parameters. Please check all annotations are imported outside of TYPE_CHECKING blocks. Error: "
+ str(e)

) from None

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

if options is None:
options = expand_params(self)
try:
options = expand_params(self)
except NameError as e:
raise NameError(
"Could not expand parameter options. Please check all annotations are imported outside of TYPE_CHECKING blocks. "
+ e.args[0]
Comment on lines +486 to +487
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Could not expand parameter options. Please check all annotations are imported outside of TYPE_CHECKING blocks. "
+ e.args[0]
"Could not expand parameter options. Please check all annotations are imported outside of TYPE_CHECKING blocks. Error: "
+ str(e)

) from None

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