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 Instruction(line: DatLine, dat_idx: int | None = None, **kwargs)

Bases: ABC

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

n_attributes: int | range | Collection
is_implemented: bool
__init__(line: DatLine, dat_idx: int | 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.

line: DatLine
idx: dict[str, int]
_assert_correct_number_of_args(idx: int) None

Check if given number of arguments is ok.

__str__() str

Give name of current command. Used by LW to identify elements.

property name: str

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

to_line(*args, **kwargs) list[str]

Convert the object back into a .dat line.

increment_dat_position(increment: int = 1) None

Increment dat index for when another instruction is inserted.

insert_dat_line(*args, dat_filecontent: list[DatLine], 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_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.

classmethod from_args(dat_idx: int, *args, **kwargs) Self

Instantiate instruction from its arguments directly.

classmethod _args_to_line(*args, **kwargs) str

Create the line of the dat file from arguments of the command.

_abc_impl = <_abc._abc_data object at 0x7f370b42f840>
class Dummy(line: DatLine, warning: bool = False, **kwargs)

Bases: Instruction

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

is_implemented: bool = False
__init__(line: DatLine, warning: bool = False, **kwargs) None

Create the dummy object, raise a warning if necessary.

Parameters:
  • line (DatLine) – 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 at 0x7f36fbb3fec0>
class Comment(line: DatLine, dat_idx: int | None = None, **kwargs)

Bases: Dummy

An object corresponding to a comment.

__init__(line: DatLine, dat_idx: int | None = None, **kwargs) 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 at 0x7f36fab386c0>
class LineJump(line: DatLine, dat_idx: int | None = None, **kwargs)

Bases: Comment

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

_abc_impl = <_abc._abc_data object at 0x7f36fab387c0>