Skip to content

Commit

Permalink
fix(commands): resolve unstringified annotation before caching (#1120)
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Oct 19, 2023
1 parent 857dd2d commit c2a8dde
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions changelog/1120.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
|commands| Fix edge case in evaluation of multiple identical annotations with forwardrefs in a single signature.
13 changes: 7 additions & 6 deletions disnake/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1134,13 +1134,14 @@ def evaluate_annotation(
if implicit_str and isinstance(tp, str):
if tp in cache:
return cache[tp]
evaluated = (
eval( # noqa: PGH001, S307 # this is how annotations are supposed to be unstringifed
tp, globals, locals
)
)

# this is how annotations are supposed to be unstringifed
evaluated = eval(tp, globals, locals) # noqa: PGH001, S307
# recurse to resolve nested args further
evaluated = evaluate_annotation(evaluated, globals, locals, cache)

cache[tp] = evaluated
return evaluate_annotation(evaluated, globals, locals, cache)
return evaluated

if hasattr(tp, "__args__"):
implicit_str = True
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,8 +758,8 @@ def test_normalise_optional_params(params, expected) -> None:
("Tuple[dict, List[Literal[42, 99]]]", Tuple[dict, List[Literal[42, 99]]], True),
# 3.10 union syntax
pytest.param(
"int | Literal[False]",
Union[int, Literal[False]],
"int | float",
Union[int, float],
True,
marks=pytest.mark.skipif(sys.version_info < (3, 10), reason="syntax requires py3.10"),
),
Expand Down

0 comments on commit c2a8dde

Please sign in to comment.