core.instruction module

Define a master class for Element and Command.

Todo

The line is edited to remove personalized name, weight and always have the same arguments at the same position. But after I shall re-add them with reinsert_optional_commands_in_line. This is very patchy and un-Pythonic.

class Comment(line: list[str], dat_idx: int)

Bases: Dummy

An object corresponding to a comment.

__init__(line: list[str], dat_idx: int) None

Create the object, but never raise a warning.

Parameters:
  • line (list[str]) – Arguments of the line in the .dat file.

  • dat_idx (int) – Line number in the .dat file.

_abc_impl = <_abc._abc_data object>
class Dummy(line: list[str], dat_idx: int, warning: bool = False)

Bases: Instruction

An object corresponding to a non-implemented element or command.

__init__(line: list[str], dat_idx: int, warning: bool = False) None

Create the dummy object, raise a warning if necessary.

Parameters:
  • line (list[str]) – Arguments of the line in the .dat file.

  • dat_idx (int) – Line number in the .dat file.

  • warning (bool, optional) – To raise a warning when the element is not implemented. The default is False.

_abc_impl = <_abc._abc_data object>
is_implemented: bool = False
class Instruction(line: list[str], dat_idx: int, name: str | None = None, **kwargs)

Bases: ABC

An object corresponding to a line in a .dat file.

__init__(line: list[str], dat_idx: int, name: str | None = None, **kwargs) None

Instantiate corresponding line and line number in .dat file.

Parameters:
  • line (list[str]) – Line containing the instructions.

  • dat_idx (int) – Position in the .dat. Note that this index will vary if some instructions (empty lines, comments in particular) are removed from the dat content.

  • name (str | None) – Name of the instruction.

_abc_impl = <_abc._abc_data object>
_assert_correct_number_of_args(idx: int) None

Check if given number of arguments is ok.

idx: dict[str, int]
increment_dat_position(increment: int = 1) None

Increment dat index for when another instruction is inserted.

insert_line(*args, dat_filecontent: list[Collection[str]], previously_inserted: int = 0, **kwargs) None

Insert the current object in the dat_filecontent object.

Parameters:
  • dat_filecontent (list[Collection[str]]) – The list of instructions, in the form of a list of lines.

  • previously_inserted (int, optional) – Number of Instruction that were already inserted in the given dat_filecontent.

insert_object(instructions: MutableSequence[Self]) None

Insert current instruction in a list full of other instructions.

is_implemented: bool
line: list[str]
n_attributes: int | range | Collection
property name: str

Give personal. name of instruction if exists, default otherwise.

reinsert_optional_commands_in_line() None

Reput name and weight.

to_line(*args, inplace: bool = False, with_name: bool = False, **kwargs) list[str]

Convert the object back into a .dat line.

Parameters:
  • inplace (bool, optional) – To edit the self.line attribute. The default is False.

  • with_name (bool, optional) – To add the name of the element to the line. The default is False.

Returns:

A line of the .dat file. The arguments are each an element in the list.

Return type:

list[str]

Raises:

NotImplementedError:with_name = True & inplace = True currently raises an error as I do not want the name of the element to be inserted several times.

class LineJump(line: list[str], dat_idx: int)

Bases: Comment

An object corresponding to an empty line. Basically a comment.

_abc_impl = <_abc._abc_data object>