hyped.common.utils module

A Collection of utility functions used throughout the project.

hyped.common.utils.is_package_installed(package_name: str) bool[source]

Check if a package with the given name is installed.

Parameters:

package_name (str) – The name of the package.

Returns:

True if the package is installed, False otherwise.

Return type:

bool

hyped.common.utils.is_python_version_less_than(major, minor: int = 0, micro: int = 0)[source]

Check if the current Python version is less than the provided version.

Parameters:
  • major (int) – Major version to compare.

  • minor (int) – Minor version to compare. Defaults to 0.

  • micro (int) – Micro version to compare. Defaults to 0.

Returns:

True if the current Python version is less than the provided version.

Return type:

bool

hyped.common.utils.tmp_setattr(instance: object, attribute: str, value: Any) Generator[None, None, None][source]

Temporarily set an attribute on an object and restore its original value afterward.

This context manager temporarily sets the specified attribute on the given object to a new value. Upon exiting the context, the original value is restored. If the attribute did not exist prior to the context, it will be removed when the context exits.

Parameters:
  • instance (object) – The object on which the attribute will be temporarily set.

  • attribute (str) – The name of the attribute to be set.

  • value (Any) – The temporary value to assign to the attribute.

Yields:

None – Yields control to the context block.

Raises:

AttributeError – If the attribute cannot be set or removed on the given object.