Skip to content

Commit

Permalink
[commands] Add support for type statement and NewType
Browse files Browse the repository at this point in the history
  • Loading branch information
bijij committed May 5, 2024
1 parent 692db7e commit 9fab99a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions discord/utils.py
Expand Up @@ -68,6 +68,7 @@
import os
import sys
import types
import typing
import warnings
import logging

Expand Down Expand Up @@ -1080,6 +1081,7 @@ def as_chunks(iterator: _Iter[T], max_size: int) -> _Iter[List[T]]:


PY_310 = sys.version_info >= (3, 10)
PY_312 = sys.version_info >= (3, 12)


def flatten_literal_params(parameters: Iterable[Any]) -> Tuple[Any, ...]:
Expand Down Expand Up @@ -1118,6 +1120,16 @@ def evaluate_annotation(
cache[tp] = evaluated
return evaluated

if PY_312 and getattr(tp.__repr__, '__objclass__', None) is typing.TypeAliasType: # type: ignore
temp_locals = dict(**locals, **{t.__name__: t for t in tp.__type_params__})
annotation = evaluate_annotation(tp.__value__, globals, temp_locals, cache.copy())
if hasattr(tp, '__args__'):
annotation = annotation[tp.__args__]
return annotation

if hasattr(tp, '__supertype__'):
return evaluate_annotation(tp.__supertype__, globals, locals, cache)

if hasattr(tp, '__metadata__'):
# Annotated[X, Y] can access Y via __metadata__
metadata = tp.__metadata__[0]
Expand Down

0 comments on commit 9fab99a

Please sign in to comment.