diff options
| author | capellancitizen <thecapellancitizen@gmail.com> | 2025-03-09 21:21:48 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-03-09 21:21:48 -0400 |
| commit | 99509df8d8abf1e7b701a4a09cf170a362f6d878 (patch) | |
| tree | a461549502fa9f37dc287789b6c7db81dfcd5368 /lib/svg | |
| parent | 0d2fc24f25f87562f0755b53dad6204efad1330d (diff) | |
Mypy type correctness (#3199)
Diffstat (limited to 'lib/svg')
| -rw-r--r-- | lib/svg/path.py | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/svg/path.py b/lib/svg/path.py index 548a82f2..5e6e7007 100644 --- a/lib/svg/path.py +++ b/lib/svg/path.py @@ -9,7 +9,7 @@ from .tags import SVG_GROUP_TAG, SVG_LINK_TAG from .units import get_viewbox_transform -def apply_transforms(path, node): +def apply_transforms(path: inkex.Path, node: inkex.BaseElement) -> inkex.Path: transform = get_node_transform(node) # apply the combined transform to this node's path @@ -18,20 +18,21 @@ def apply_transforms(path, node): return path -def compose_parent_transforms(node, mat): +def compose_parent_transforms(node: inkex.BaseElement, mat: inkex.Transform) -> inkex.Transform: # This is adapted from Inkscape's simpletransform.py's composeParents() # function. That one can't handle nodes that are detached from a DOM. trans = node.get('transform') if trans: mat = inkex.transforms.Transform(trans) @ mat - if node.getparent() is not None: - if node.getparent().tag in [SVG_GROUP_TAG, SVG_LINK_TAG]: - mat = compose_parent_transforms(node.getparent(), mat) + parent = node.getparent() + if parent is not None: + if parent.tag in [SVG_GROUP_TAG, SVG_LINK_TAG]: + mat = compose_parent_transforms(parent, mat) return mat -def get_node_transform(node: inkex.BaseElement): +def get_node_transform(node: inkex.BaseElement) -> inkex.Transform: """ if getattr(node, "composed_transform", None): return node.composed_transform() @@ -52,7 +53,7 @@ def get_node_transform(node: inkex.BaseElement): return transform -def get_correction_transform(node, child=False): +def get_correction_transform(node: inkex.BaseElement, child=False) -> str: """Get a transform to apply to new siblings or children of this SVG node Arguments: @@ -71,7 +72,11 @@ def get_correction_transform(node, child=False): else: # we can ignore the transform on the node itself since it won't apply # to the objects we add - transform = get_node_transform(node.getparent()) + parent = node.getparent() + if parent is not None: + transform = get_node_transform(parent) + else: + transform = inkex.Transform() # now invert it, so that we can position our objects in absolute # coordinates |
