Skip to content

Make attribute access more consistent

What does the merge request do?

As a general guideline, properties that have a 1:1 equivalency between SVG and Python and return a mutable datatype should modify the tree when the value is modified. This was already the case for transform, style and classes, but not for whenever object.style(attribute) returned a list. Also, when setting a style attribute with an element, the step to add the element to the defs is automatically done. This contributes to #534 (filters is nice now, we just need to do it for clips and masks as well).

For element.path, this is still not the case for performance reasons, but element.path can be used as context manager that modifies the element when leaving the with block, in all cases where element.path is a 1:1 representation (e.g. path and polyline). This required to make the function signature of get_path consistent in all child classes of ShapeElement. This closes #550 (closed).

Implementation notes

  • The functionality for an observable list / dict has been factored out into intermediate classes.
  • I will probably refactor the style access a bit more, to further speed it up for most use cases and to address #544 (closed) .
  • A new documentation page has been added describing the rationale for attribute access, and giving examples of the new API.

Summary for release notes

Checklist

  • Add unit tests (if applicable)
  • Changes to inkex/ are well documented
  • Clean merge request history
Edited by Jonathan Neuhauser

Merge request reports