Source

Imported as:

from pedal.source import *
verify()

Parses the current main code of the submission and reports any syntax errors as feedback. You can actually pass in explicit code and filename as strings, but by default uses the current submission.

get_program() str

Retrieves the current main code of the submission.

set_source(code: str, filename: str)

Convenience function for overriding the current submission with some other code. Any checks that use the main code of the submission will use this code instead. No longer necessary, mostly a legacy solution in light of the new contextualization through submissions.

restore_code()

Undoes the latest set_source.

Sections

separate_into_sections(pattern='^(##### Part .+)$')

Breaks the current main code file into multiple sections using the regular expression pattern. The first section will be set as the main code submission, and you can advance through to the next one by calling next_section(), or verify that there are the right number of sections with check_section_exists().

check_section_exists(number: int)

Verifies that the right number of expected sections exist after a separation is performed. Otherwise, creates new feedback indicating the issue. The prologue before the first section is 0, while subsequent ones are 1, 2, 3, etc. So if you have 3 sections in your code plus the prologue, you should pass in 3 and not 4 to verify that all of them exist.

next_section()

Moves the current submission main code to be the next section that was found during separation. If used when there are no more sections, the not_enough_sections feedback is given.

stop_sections()

Removes any separations and restores the main code submission back to a single file.

Source Feedbacks

Feedback Function: No Source Code
  • Label: blank_source
  • Justification: After stripping the code, there were no characters.
  • Response: Source code file is blank.
Feedback Function: Not Enough Sections
  • Label: not_enough_sections
  • Justification: Section index exceeded the length of the separated sections list.
  • Response: Tried to advance to next section but the section was not found. Tried to load section {count}, but there were only {found} sections.
Feedback Function: Source File Not Found
  • Label: source_file_not_found
  • Justification: IOError while opening file to set_source
  • Response: The given filename {name:filename} was either not found or could not be opened. Please make sure the file is available.
Feedback Function: Syntax Error
  • Label: syntax_error
  • Justification: Syntax error was triggered while calling ast.parse
  • Response: Bad syntax on line {lineno:line}. {traceback_preamble}{traceback_message} {exception_message}{suggestion_message}
Feedback Function: Incorrect Number of Sections
  • Label: incorrect_number_of_sections
  • Response: Incorrect number of sections in your file. Expected {count}, but only found {found}