Add experimental UITypedTextInput class by pushfoo · Pull Request #2308 · pythonarcade/arcade · GitHub
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
250 changes: 250 additions & 0 deletions arcade/gui/experimental/typed_text_input.py
29 changes: 29 additions & 0 deletions arcade/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
from typing import Any, Callable, Generator, Generic, Iterable, Sequence, Type, TypeVar

__all__ = [
"as_type",
"type_name",
"copy_dunders_unimplemented",
"is_iterable",
"is_nonstr_iterable",
Expand Down Expand Up @@ -49,6 +51,33 @@ def __iter__(self) -> Generator[_T, None, None]:
yield item


def as_type(item: Any) -> type:
"""If item is not a type, return its type. Otherwise, return item as-is.

Args:
item: A :py:class:`type` or instance of one.
"""
if isinstance(item, type):
return item
else:
return item.__class__


def type_name(item: Any) -> str:
"""Get the name of item if it's a type or the name of its type if it's an instance.

This is meant to help shorten debugging-related code and developer
utilities. It isn't meant to be a performant tool.

Args:
item: A :py:class:`type` or an instance of one.
"""
if isinstance(item, type):
return item.__name__
else:
return item.__class__.__name__


def is_iterable(item: Any) -> bool:
"""Use :py:func:`iter` to infer whether ``item`` is iterable.

Expand Down
3 changes: 2 additions & 1 deletion util/update_quick_index.py