$80 GRAYBYTE WORDPRESS FILE MANAGER $48

SERVER : in-mum-web1330.main-hosting.eu #1 SMP Mon Feb 10 22:45:17 UTC 2025
SERVER IP : 84.32.84.45 | ADMIN IP 216.73.216.215
OPTIONS : CRL = ON | WGT = ON | SDO = OFF | PKEX = OFF
DEACTIVATED : NONE

/opt/alt/python311/lib/python3.11/site-packages/typish/functions/

HOME
Current File : /opt/alt/python311/lib/python3.11/site-packages/typish/functions//_instance_of.py
from typish._state import DEFAULT, State


def instance_of(obj: object, *args: object, state: State = DEFAULT) -> bool:
    """
    Check whether ``obj`` is an instance of all types in ``args``, while also
    considering generics.

    If you want the instance check to be customized for your type, then make
    sure it has a __instancecheck__ defined (not in a base class). You will
    also need to register the get_type function by calling
    typish.register_get_type with that particular type and a handling callable.
    :param obj: the object in subject.
    :param args: the type(s) of which ``obj`` is an instance or not.
    :param state: any state that is used by typish.
    :return: ``True`` if ``obj`` is an instance of all types in ``args``.
    """
    return all(_instance_of(obj, clsinfo, state) for clsinfo in args)


def _instance_of(obj: object, clsinfo: object, state: State = DEFAULT) -> bool:
    from typish.classes._literal import LiteralAlias, is_literal_type
    from typish.functions._subclass_of import subclass_of
    from typish.functions._get_type import get_type
    from typish.functions._is_from_typing import is_from_typing

    if not is_from_typing(clsinfo) and '__instancecheck__' in dir(clsinfo):
        return isinstance(obj, clsinfo)

    if is_literal_type(clsinfo):
        alias = LiteralAlias.from_literal(clsinfo)
        return isinstance(obj, alias)

    type_ = get_type(obj, use_union=True, state=state)
    return subclass_of(type_, clsinfo)

Current_dir [ NOT WRITEABLE ] Document_root [ WRITEABLE ]


[ Back ]
NAME
SIZE
LAST TOUCH
USER
CAN-I?
FUNCTIONS
..
--
8 May 2024 6.34 PM
root / root
0755
__pycache__
--
8 May 2024 6.34 PM
root / root
0755
__init__.py
0 KB
8 May 2024 6.34 PM
root / root
0644
_common_ancestor.py
1.146 KB
8 May 2024 6.34 PM
root / root
0644
_get_alias.py
1.206 KB
8 May 2024 6.34 PM
root / root
0644
_get_args.py
0.421 KB
8 May 2024 6.34 PM
root / root
0644
_get_mro.py
0.919 KB
8 May 2024 6.34 PM
root / root
0644
_get_origin.py
1.126 KB
8 May 2024 6.34 PM
root / root
0644
_get_simple_name.py
0.54 KB
8 May 2024 6.34 PM
root / root
0644
_get_type.py
4.482 KB
8 May 2024 6.34 PM
root / root
0644
_get_type_hints_of_callable.py
1.595 KB
8 May 2024 6.34 PM
root / root
0644
_instance_of.py
1.497 KB
8 May 2024 6.34 PM
root / root
0644
_is_from_typing.py
0.247 KB
8 May 2024 6.34 PM
root / root
0644
_is_optional_type.py
0.633 KB
8 May 2024 6.34 PM
root / root
0644
_is_type_annotation.py
0.855 KB
8 May 2024 6.34 PM
root / root
0644
_subclass_of.py
5.729 KB
8 May 2024 6.34 PM
root / root
0644

GRAYBYTE WORDPRESS FILE MANAGER @ 2026 CONTACT ME
Static GIF