Skip to content

Helpers

lahuta.core.helpers

Helper functions to retrieve class methods and/or attributes. It is intended to be used by and for NeighborPairs, even though the functions are generic.

get_class_methods

get_class_methods(cls)

Retrieve all the methods of the specified class.

Parameters:

Name Type Description Default
cls NeighborPairs

The class to inspect.

required

Returns:

Type Description
list[str]

list[str]: A list of strings containing the names of all the methods of the specified class.

Source code in lahuta/core/helpers.py
10
11
12
13
14
15
16
17
18
19
def get_class_methods(cls: "NeighborPairs") -> list[str]:
    """Retrieve all the methods of the specified class.

    Args:
        cls (NeighborPairs): The class to inspect.

    Returns:
        list[str]: A list of strings containing the names of all the methods of the specified class.
    """
    return [attr for attr in dir(cls) if callable(getattr(cls, attr))]

get_class_properties

get_class_properties(cls)

Retrieve all the properties of the specified class.

Parameters:

Name Type Description Default
cls NeighborPairs

The class to inspect.

required

Returns:

Type Description
list[str]

list[str]: A list of strings containing the names of all the properties of the specified class.

Source code in lahuta/core/helpers.py
22
23
24
25
26
27
28
29
30
31
def get_class_properties(cls: "NeighborPairs") -> list[str]:
    """Retrieve all the properties of the specified class.

    Args:
        cls (NeighborPairs): The class to inspect.

    Returns:
        list[str]: A list of strings containing the names of all the properties of the specified class.
    """
    return [attr for attr in dir(cls) if isinstance(getattr(cls, attr), property)]

get_class_attributes

get_class_attributes(cls)

Retrieve all the attributes (not methods or properties) of the specified class.

Parameters:

Name Type Description Default
cls NeighborPairs

The class to inspect.

required

Returns:

Type Description
list[str]

list[str]: A list of strings containing the names of all the attributes (not methods or properties)

list[str]

of the specified class.

Source code in lahuta/core/helpers.py
34
35
36
37
38
39
40
41
42
43
44
def get_class_attributes(cls: "NeighborPairs") -> list[str]:
    """Retrieve all the attributes (not methods or properties) of the specified class.

    Args:
        cls (NeighborPairs): The class to inspect.

    Returns:
        list[str]: A list of strings containing the names of all the attributes (not methods or properties)
        of the specified class.
    """
    return [attr for attr in dir(cls) if not attr.startswith("__") and not callable(getattr(cls, attr))]