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
29 changes: 13 additions & 16 deletions typemap/type_eval/_eval_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,21 @@
import re
import types
import typing
from typing import _AnnotatedAlias as typing_AnnotatedAlias # type: ignore [attr-defined] # noqa: PLC2701
from typing_extensions import _AnnotatedAlias as typing_AnnotatedAlias

from typemap import type_eval
from typemap.type_eval import _apply_generic, _typing_inspect
from typemap.type_eval._eval_typing import _eval_types
from typemap.typing import (
Attrs,
Capitalize,
DropAnnotations,
FromUnion,
GenericCallable,
GetAnnotations,
GetArg,
GetArgs,
GetAttr,
GetAnnotations,
DropAnnotations,
IsSubSimilar,
IsSubtype,
Iter,
Expand Down Expand Up @@ -474,11 +474,8 @@ def _ann(x):
return f


@type_eval.register_evaluator(Attrs)
@_lift_over_unions
def _eval_Attrs(tp, *, ctx):
hints = get_annotated_type_hints(tp, include_extras=True)

def _hints_to_members(hints, ctx):
"""Convert a hints dictionary to a tuple of Member types."""
return tuple[
*[
Member[
Expand All @@ -492,21 +489,21 @@ def _eval_Attrs(tp, *, ctx):
]


@type_eval.register_evaluator(Attrs)
@_lift_over_unions
def _eval_Attrs(tp, *, ctx):
hints = get_annotated_type_hints(tp, include_extras=True)
return _hints_to_members(hints, ctx)


@type_eval.register_evaluator(Members)
@_lift_over_unions
def _eval_Members(tp, *, ctx):
hints = {
**get_annotated_type_hints(tp, include_extras=True),
**get_annotated_method_hints(tp),
}

attrs = [
Member[
typing.Literal[n], _eval_types(t, ctx), _mk_literal_union(*qs), d
]
for n, (t, qs, d) in hints.items()
]
return tuple[*attrs]
return _hints_to_members(hints, ctx)


##################################################################
Expand Down
10 changes: 6 additions & 4 deletions typemap/type_eval/_eval_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
import types
import typing

from typing import _GenericAlias as typing_GenericAlias # type: ignore [attr-defined] # noqa: PLC2701
from typing import _CallableGenericAlias as typing_CallableGenericAlias # type: ignore [attr-defined] # noqa: PLC2701
from typing import _LiteralGenericAlias as typing_LiteralGenericAlias # type: ignore [attr-defined] # noqa: PLC2701
from typing import _AnnotatedAlias as typing_AnnotatedAlias # type: ignore [attr-defined] # noqa: PLC2701
from typing import ( # type: ignore [attr-defined] # noqa: PLC2701
_GenericAlias as typing_GenericAlias,
_CallableGenericAlias as typing_CallableGenericAlias,
_LiteralGenericAlias as typing_LiteralGenericAlias,
_AnnotatedAlias as typing_AnnotatedAlias,
)


if typing.TYPE_CHECKING:
Expand Down