PY-54

Validate a Configuration Record

  • Medium
  • Configuration Records
  • Python

Task

Define the RunConfig record below and write validate_configs(configs):

Return (valid, rejected). valid contains the original configuration objects that pass. rejected contains (index, name, reason) tuples. Apply only the first failing rule to each item, in this order:

  1. a name already seen earlier: "duplicate name";
  2. an empty input_path: "empty input path";
  3. an unsafe output_name: "unsafe output name";
  4. batch_size is not a positive integer: "invalid batch size";
  5. shuffle is true while seed is None: "shuffle requires seed".

An output name is safe only when it is non-empty and every character is a letter, digit, hyphen, or underscore. A boolean is not a valid batch size even though Python treats bool as a kind of integer. A rejected name still counts as seen when a later item repeats it.

Example

The first item is valid. The second becomes (1, "base", "duplicate name").

Your implementation

Edit solution.py, keep the record definition above, and keep this function signature:

Do not change a configuration or the input list, print, or ask for input.