@@ -101,19 +101,20 @@ def get_cls_name(cls: Any, args: bool = False) -> str:
101101 the original class when the name cannot be obtained.
102102 If alias exists, alias is returned instead.
103103 """
104- if (alias := get_aliased_name (cls )) is not None :
104+ normal_cls = get_origin (cls ) or cls
105+ if (alias := get_aliased_name (normal_cls )) is not None :
105106 return alias + f" ({ name } )"
106- elif hasattr (cls , "__name__" ):
107- name = cls .__name__
108- elif hasattr (cls , "_name" ) and cls ._name :
109- name = cls ._name
107+ elif hasattr (normal_cls , "__name__" ):
108+ name = normal_cls .__name__
109+ elif hasattr (normal_cls , "_name" ) and normal_cls ._name :
110+ name = normal_cls ._name
110111 else :
111- name = str (cls )
112+ name = str (normal_cls )
112113
113114 if args and (type_args := get_args (cls )):
114115 name = (
115116 name +
116- f"[{ ', ' .join ([NewObjectFrameBase .get_cls_name (x ) for x in type_args ]) } ]"
117+ f"[{ ', ' .join ([NewObjectFrameBase .get_cls_name (x , True ) for x in type_args ]) } ]"
117118 )
118119
119120 return name
@@ -209,21 +210,29 @@ def remove_classes(types: list):
209210 )
210211
211212 origin = get_origin (input_type )
213+ if issubclass_noexcept (origin , Generic ):
214+ # Patch for Python versions < 3.10
215+ input_type .__name__ = origin .__name__
216+
212217 # Unpack Union items into a tuple
213- if origin is Union or issubclass_noexcept (origin , Iterable ):
214- new_types = dict ()
218+ if origin is Union or issubclass_noexcept (origin , ( Iterable , Generic ) ):
219+ new_types = []
215220 for type_ in chain .from_iterable ([cls .convert_types (r ) for r in get_args (input_type )]):
216- new_types [ type_ ] = 0 # Use dictionary's keys as OrderedSet, with dummy value 0
221+ new_types . append ( type_ )
217222
218223 new_types = tuple (new_types )
219224 if origin is Union :
220- return new_types
225+ return new_types # Just expand unions
221226
222- return (origin [new_types ],)
227+ # Process abstract classes and polymorphism
228+ new_origins = []
229+ for origin in cls .convert_types (origin ):
230+ if issubclass_noexcept (origin , (Generic , Iterable )):
231+ new_origins .append (origin [new_types ])
232+ else :
233+ new_origins .append (origin )
223234
224- if issubclass_noexcept (origin , Generic ):
225- # Patch for Python versions < 3.10
226- input_type .__name__ = origin .__name__
235+ return tuple (new_origins )
227236
228237 if input_type .__module__ == "builtins" :
229238 # Don't consider built-int types for polymorphism
@@ -259,7 +268,7 @@ def modified(self) -> bool:
259268
260269 def update_window_title (self ):
261270 "Set's the window title according to edit context."
262- self .origin_window .title (f"{ 'New' if self .old_gui_data is None else 'Edit' } { self .get_cls_name (self .class_ )} object" )
271+ self .origin_window .title (f"{ 'New' if self .old_gui_data is None else 'Edit' } { self .get_cls_name (self .class_ , True )} object" )
263272
264273 def close_frame (self ):
265274 if self .allow_save and self .modified :
0 commit comments