Skip to content

Degrade to identity on a malformed transform substring instead of raising ValueError - #247

Open
eeshsaxena wants to merge 1 commit into
mathandy:masterfrom
eeshsaxena:fix/parse-transform-malformed
Open

Degrade to identity on a malformed transform substring instead of raising ValueError#247
eeshsaxena wants to merge 1 commit into
mathandy:masterfrom
eeshsaxena:fix/parse-transform-malformed

Conversation

@eeshsaxena

Copy link
Copy Markdown

parse_transform already tolerates malformed input in most places: it warns and returns the identity matrix for an unknown transform type or a wrong number of arguments. But two cases still raise a bare ValueError:

  • non-numeric values, e.g. parse_transform('matrix(1 x 3 4 5 6)') -> float('x') raises;
  • a substring without exactly one (, e.g. a stray 'matrix', so the type, values = substr.split('(') unpack fails.

I guarded both so they warn and fall back to the identity matrix, matching the existing _check_num_parsed_values / unknown-type behavior. Valid transforms are unchanged.

Added a test with the malformed variants; it raises ValueError on master and passes with the change, and the rest of the parsing tests still pass.

_parse_transform_substr raised a bare ValueError when a transform substring had
non-numeric values (float('x')) or the wrong number of parentheses (the
type(...) split). parse_transform already warns and returns the identity matrix
for an unknown transform type or a wrong argument count, so handle these the
same way instead of raising.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant