Skip to content

Commit

Permalink
Fixed Pylance docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
NikosDelijohn committed Aug 12, 2024
1 parent 6675457 commit 621329c
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions src/asm.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
log.addHandler(log_stream)
log.addHandler(log_file)

@dataclass
@dataclass
class Codeline:
"""Represents a line of assembly code"""
lineno : int
Expand Down Expand Up @@ -163,20 +163,21 @@ def __repr__(self):
def get_mnemonics(self) -> set:
"""Returns a set with the ISA-lang mnemonics.
Args:
- Parameters:
- None
Returns:
- Returns:
- set: A set with all the ISA-lang mnemonics."""

return self.mnemonics

def is_instruction(self, assembly_line : str) -> bool:
"""Checks if `assembly_line`'s first sub-string is present the class `keywords` set.
Args:
- Parameters:
- assembly_line (str): an assembly mnemonic.
Returns:
- Returns:
- bool: True if `assembly_line` is in `mnemonics`, False otherwise.
"""

Expand Down Expand Up @@ -230,17 +231,19 @@ def __init__(self, isa : ISA, assembly_source : pathlib.Path, chunksize : int =
def get_asm_source(self) -> pathlib.Path:
"""Returns the assembly source file `pathlib.Path`.
Args:
- Parameters:
- None
Returns:
- Returns:
- pathlib.Path: The assembly source `pathlib.Path`."""

return self.asm_file

def get_code(self) -> list[Codeline]:
"""Returns the parsed code as a list of `Codelines`.
Args:
Parameters:
- None
Returns:
- list: A list of `Codeline` entries."""
Expand All @@ -250,12 +253,12 @@ def get_code(self) -> list[Codeline]:
def get_candidate(self, lineno : int) -> Codeline:
"""Returns the Codeline in candidates with the specified lineno
Args:
- Parameters:
- lineno (int): the line number of the candidate to be found.
Returns:
- Codeline : the `Codeline` with `Codeline.lineno == lineno`
if found. Raises LookupError otherwise."""
- Returns:
- Codeline: the `Codeline` with `Codeline.lineno == lineno`
if found. Raises LookupError otherwise."""

for chunk in self.candidates:

Expand All @@ -271,11 +274,11 @@ def get_random_candidate(self, pop_candidate = True) -> Codeline:
"""In a uniform random manner selects one `Codeline` and returns it
while also optionally removing it from the `candidate` collection
Args:
- Parameters:
- pop_candidate (bool): When True, deletes the `Codeline` from the collection
after identifying it.
Returns:
- Returns:
- Codeline: A random `Codeline` from a random `self.candidates` chunk."""

random_chunk = random.randint(0, len(self.candidates) - 1)
Expand All @@ -298,11 +301,12 @@ def remove(self, codeline : Codeline) -> None:
as a source and skips the the line which corresponds to `codeline`'s
`lineno` attribute.
Args:
- Parameters:
- codeline (Codeline): The `Codeline` to be removed from the
assembly file.
Returns: Nothing"""
- Returns:
- None"""

with open(self.asm_file) as source, tempfile.NamedTemporaryFile('w', delete = False) as new_source:

Expand Down Expand Up @@ -338,7 +342,10 @@ def restore(self) -> None:
file. The `self.candidates` lineno fields are updated if >= than the
entry which is being restored.
Returns: Nothing"""
Parameters:
- None
Returns:
- None"""

if not self.asm_file_changelog:
log.debug(f"Changelog is empty, nothing to restore!")
Expand Down Expand Up @@ -390,15 +397,15 @@ def compile(self, exit_on_error : bool = False, *instructions : str) -> bool:
"""Executes a sequence of bash instructions to compile the `self.asm_file`.
Uses subprocess for each instruction and optionally exits on error.
Args:
- exit_on_error (bool) : If an error is encountered during
- Parameters:
- exit_on_error (bool): If an error is encountered during
compilation and this is True, then the program terminates.
Otherwise it continues.
- *instructions (str) : A sequence of /bin/bash commands
- *instructions (str): A sequence of /bin/bash commands
required in order to compile `self.asm_file`.
Returns:
- bool : True if no message was written to `stderr` from any
- Returns:
- bool: True if no message was written to `stderr` from any
of the executed instructions (subprocesses). False otherwise. """

if not len(instructions):
Expand Down Expand Up @@ -441,9 +448,10 @@ def save(self):
linenos seperated with a dash. If `self.asm_file_changelog` is
empty, it does nothing.
Args:
Returns: Nothing"""
Parameters:
- None
Returns:
- Nothing"""

if not self.asm_file_changelog:
log.debug(f"No changes present to be saved.")
Expand Down

0 comments on commit 621329c

Please sign in to comment.