def get_all_subclasses(typ, recursive: bool = True, _memo = None) -> Sequence[Type[Any]]:
_memo = _memo or set()<EOL>if typ in _memo:<EOL><INDENT>return []<EOL><DEDENT>_memo.add(typ)<EOL>if is_generic_type(typ):<EOL><INDENT>sub_list = get_origin(typ).__subclasses__()<EOL><DEDENT>else:<EOL><INDENT>sub_list = typ.__subclasses__()<EOL><DEDENT>result = []<EOL>for t in sub_list:<EOL><INDENT>to = get_origin(t) or t<EOL>try:<EOL><INDENT>if to is not typ and to not in result and is_subtype(to, typ, bound_typevars={}):<EOL><INDENT>result.append(to)<EOL><DEDENT><DEDENT>except:<EOL><INDENT>pass<EOL><DEDENT><DEDENT>if recursive:<EOL><INDENT>for typpp in sub_list:<EOL><INDENT>for t in get_all_subclasses(typpp, recursive=True, _memo=_memo):<EOL><INDENT>if t not in sub_list and is_subtype(t, typ, bound_typevars={}):<EOL><INDENT>result.append(t)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>return result<EOL>
Returns all subclasses, and supports generic types. It is recursive by default
See discussion at https://github.com/Stewori/pytypes/issues/31

:param typ:
:param recursive: a boolean indicating whether recursion is needed
:param _memo: internal variable used in recursion to avoid exploring subclasses that were already explored
:return: