ClammingPy 1.8

https://sourceforge.net/projects/clamming/

Module clamming

Class ClamInfo

Description

The information extracted for a function in the documented class.

Public members are:

  • name (str): required, the name of the function
  • args (list of str): optional, the arguments of the function
  • source (str): optional, the source code of the function, including its definition
  • docstring (str or None): optional, the docstring of the function
Example
 >>> clam_info = ClamInfo("add", args=tuple("a", "b"), source="def add(a, b): return a+b", docstring="Add two args.")
 >>> clam_info.name
 > add
 >>> clam_info.args
 > ["a", "b"]
 >>> clam_info.source
 > "def add(a, b): return a+b"
 >>> clam_info.docstring
 > "Add two args."
 >>> clam_info = ClamInfo("add", args=tuple("a", "b"), source="def add(a, b): return a+b")
 >>> clam_info.docstring
 > None
Raises
  • TypeError: if a given argument is not of the expected type.

Constructor

Create a data class for a documented function.

Parameters
  • name: (str) Name of the documented function
  • args: (list|tuple) List of its arguments
  • source: (str) Source code of the function
  • docstring: (str) Docstring of the function
Raises
  • TypeError: Wrong type of one of the given parameters
View Source
def __init__(self, name: str, args: list[str] | tuple[str]=(), source: str='', docstring: str | None=None):
    """Create a data class for a documented function.

    :param name: (str) Name of the documented function
    :param args: (list|tuple) List of its arguments
    :param source: (str) Source code of the function
    :param docstring: (str) Docstring of the function
    :raises: TypeError: Wrong type of one of the given parameters

    """
    self.__name = ''
    self.__args = list()
    self.__source = ''
    self.__docstring = None
    self.set_name(name)
    self.set_args(args)
    self.set_source(source)
    self.set_docstring(docstring)

Public functions

get_name

Return the name of the stored class.

View Source
def get_name(self) -> str:
    """Return the name of the stored class."""
    return self.__name

set_name

Set a new name.

Parameters
  • name: (str) New name of the documented function/class/...
Raises
  • TypeError: given class_name is not a string
View Source
def set_name(self, name: str) -> NoReturn:
    """Set a new name.

        :param name: (str) New name of the documented function/class/...
        :raises: TypeError: given class_name is not a string

        """
    if isinstance(name, (str, bytes)) is False:
        raise TypeError("Expected a 'str' for the ClamInfo.name, got {:s} instead.".format(str(type(name))))
    self.__name = name

get_args

Return a copy of the list of arguments.

View Source
def get_args(self) -> list:
    """Return a copy of the list of arguments."""
    return [i for i in self.__args]

set_args

Set the list of args.

Parameters
  • args: (list|tuple) Source code
Raises
  • TypeError: The given args is not a list or tuple
View Source
def set_args(self, args: list[str] | tuple[str]) -> NoReturn:
    """Set the list of args.

        :param args: (list|tuple) Source code
        :raises: TypeError: The given args is not a list or tuple

        """
    if isinstance(args, (list, tuple)) is False:
        raise TypeError("Expected a 'list' or 'tuple' for the ClamInfo.args. Got {:s} instead.".format(str(type(args))))
    self.__args = args

get_source

Return the source code.

View Source
def get_source(self) -> str:
    """Return the source code."""
    return self.__source

set_source

Set a new source code.

Parameters
  • source: (str) Source code
Raises
  • TypeError: The given source code is not a string
View Source
def set_source(self, source: str) -> NoReturn:
    """Set a new source code.

        :param source: (str) Source code
        :raises: TypeError: The given source code is not a string

        """
    if isinstance(source, str) is False:
        raise TypeError("Expected a 'str' for the ClamInfo.source, got {:s} instead.".format(str(type(source))))
    self.__source = source

get_docstring

Return the docstring of the class.

View Source
def get_docstring(self) -> str:
    """Return the docstring of the class."""
    return self.__docstring

set_docstring

Set a new docstring to the class.

Parameters
  • docstring
View Source
def set_docstring(self, docstring: str) -> NoReturn:
    """Set a new docstring to the class."""
    if docstring is not None:
        if isinstance(docstring, str) is False:
            raise TypeError("Expected a 'str' for the ClamInfo.docstring. Got {:s} instead.".format(str(type(docstring))))
    self.__docstring = docstring