ats_utilities.factory_type module

Module

factory_type.py

Copyright

Copyright (C) 2017 - 2026 Vladimir Roncevic <elektron.ronca@gmail.com> ats_utilities is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. ats_utilities is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.

Info

Defines factory type utility functions.

ats_utilities.factory_type._resolve_type(type_to_resolve: Any) Any[source]

Resolves nested Union types. Handles cases like Union[int, float] by flattening them into a tuple of concrete types (int, float).

Parameters:

type_to_resolve (<Any>) – Type to resolve.

Returns:

Resolved type.

Return type:

<Any>

Exceptions:

None.

ats_utilities.factory_type.check_type(instance: object, class_or_tuple: type[~typing.Any] | tuple[type[~typing.Any], ...], exc_message_path: str | None = None, exception_class: type[Exception] = <class 'ats_utilities.exceptions.ats_type_error.ATSTypeError'>) None[source]

Checks if an instance is of a specified type.

Parameters:
  • instance (<any>) – Instance to check.

  • class_or_tuple (<type | tuple[type, ...]>) – Type or tuple of types to check against.

  • exc_message_path (<str | None>) – Path and details to include in the exception message.

  • exception_class (<type[Exception]> (default ATSTypeError)) – The exception class to raise if instance is not of the specified type.

Exceptions:
Dynamically raises the provided exception_class (e.g., ATSTypeError).