Skip to content

Commit 8e65ec9

Browse files
committed
fix2
1 parent 77f3dbc commit 8e65ec9

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

tkclasswiz/annotations.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from contextlib import suppress
77
from inspect import isclass
88
from .doc import doc_category
9+
from .utilities import issubclass_noexcept
910

1011

1112
__all__ = (
@@ -97,7 +98,7 @@ def get_annotations(class_) -> dict:
9798
with suppress(AttributeError, TypeError):
9899
if isclass(class_):
99100
annotations = get_type_hints(class_.__init__)
100-
elif isclass(origin_class := get_origin(class_)) and issubclass(origin_class, Generic):
101+
elif isclass(origin_class := get_origin(class_)) and issubclass_noexcept(origin_class, Generic):
101102
# Resolve generics
102103
annotations = get_type_hints(origin_class.__init__)
103104
generic_types = get_args(origin_class.__orig_bases__[0])

tkclasswiz/object_frame/frame_base.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from abc import ABC, abstractmethod
33
from inspect import isabstract
44
from contextlib import suppress
5-
from itertools import chain
5+
from itertools import chain, product
66
from functools import cache
77

88
from ..convert import *
@@ -202,6 +202,7 @@ def remove_classes(types: list):
202202

203203
return tuple({a:0 for a in r})
204204

205+
205206
if isinstance(input_type, str):
206207
raise TypeError(
207208
f"Provided type '{input_type}' is not a type - it is a string!\n"
@@ -217,20 +218,20 @@ def remove_classes(types: list):
217218
# Unpack Union items into a tuple
218219
if origin is Union or issubclass_noexcept(origin, (Iterable, Generic)):
219220
new_types = []
220-
for type_ in chain.from_iterable([cls.convert_types(r) for r in get_args(input_type)]):
221-
new_types.append(type_)
221+
for arg_group in get_args(input_type):
222+
new_types.append(remove_classes(list(cls.convert_types(arg_group))))
222223

223-
new_types = remove_classes(new_types)
224224
if origin is Union:
225-
return new_types # Just expand unions
225+
return tuple(chain.from_iterable(new_types)) # Just expand unions
226226

227227
# Process abstract classes and polymorphism
228228
new_origins = []
229229
for origin in cls.convert_types(origin):
230230
if issubclass_noexcept(origin, Iterable):
231-
new_origins.append(origin[tuple(new_types)])
231+
new_origins.append(origin[tuple(chain.from_iterable(new_types))])
232232
elif issubclass_noexcept(origin, Generic):
233-
new_origins.append(origin[tuple(new_types[:len(origin.__parameters__)])])
233+
for comb in product(*new_types):
234+
new_origins.append(origin[comb])
234235
else:
235236
new_origins.append(origin)
236237

tkclasswiz/object_frame/window.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def _create_and_add_frame(
112112

113113
if issubclass_noexcept(class_origin, Flag):
114114
frame_class = NewObjectFrameFlag
115-
elif issubclass(class_origin, str):
115+
elif issubclass_noexcept(class_origin, str):
116116
frame_class = NewObjectFrameString
117117
elif issubclass_noexcept(class_origin, (int, float, complex)):
118118
frame_class = NewObjectFrameNumber

0 commit comments

Comments
 (0)