Models are inconsistent about types. Asked for an integer they sometimes write "3", for a boolean "true" or "yes", for a number "2.5". Rejecting every such call wastes a round trip with the model, while blindly accepting them risks silent bugs. A middle path is coercion: convert a value to the declared type when the conversion is unambiguous, leave it untouched when it is not (so validation can report it) and fill in defaults for optional arguments the model omitted. This is lenient where leniency is safe and strict everywhere else.
Implement coerce_arguments.
schema maps each argument name to a spec with type (integer, number, boolean, string) and an optional default. Return a new dict.args: a str value is coerced to integer with int(), to number with float(), and to boolean if its lowercase form is in {'true', 'yes', '1'} (True) or {'false', 'no', '0'} (False). Failed conversions leave the original value. Values already of the right type, and arguments not in schema, are copied unchanged.schema that is absent from args and has a default, add the default.float such as 3.0 given for an integer is converted only when it is integral (3.0 -> 3); 3.5 is left unchanged. Do not modify args.Wrap the int() and float() calls in try/except ValueError.
Remember that bool is a subclass of int, so check for bool before int when deciding whether a value already has the right type.
No results yet
Run your code to check it against the examples, or submit to run every test.