From dae3185ba995d23cb76d11780901437bd9108cf8 Mon Sep 17 00:00:00 2001 From: Andrew Port Date: Thu, 3 Feb 2022 18:22:45 -0800 Subject: [PATCH] aesthetic cleanup and create F_STRINGS_AVAILABLE bool --- svgpathtools/svg_to_paths.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/svgpathtools/svg_to_paths.py b/svgpathtools/svg_to_paths.py index 4023cd2..91b9f82 100644 --- a/svgpathtools/svg_to_paths.py +++ b/svgpathtools/svg_to_paths.py @@ -13,6 +13,9 @@ from sys import version_info from .parser import parse_path +# f-strings are available in Python 3.6+ +F_STRINGS_AVAILABLE = version_info < (3, 6) + COORD_PAIR_TMPLT = re.compile( r'([\+-]?\d*[\.\d]\d*[eE][\+-]?\d+|[\+-]?\d*[\.\d]\d*)' + r'(?:\s*,\s*|\s+|(?=-))' + @@ -24,7 +27,6 @@ def path2pathd(path): return path['d'] - def ellipse2pathd(ellipse): """converts the parameters from an ellipse or a circle to a string for a Path object d-attribute""" @@ -69,7 +71,7 @@ def polyline2pathd(polyline, is_polygon=False): if is_polygon and closed: points.append(points[0]) - d = 'M' + 'L'.join('{0} {1}'.format(x,y) for x,y in points) + d = 'M' + 'L'.join('{0} {1}'.format(x, y) for x, y in points) if is_polygon or closed: d += 'z' return d @@ -125,12 +127,12 @@ def rect2pathd(rect): return d -if version_info < (3, 6): - def line2pathd(node_dict): - return "M{} {}L{} {}".format(node_dict['x1'], node_dict['y1'], node_dict['x2'], node_dict['y2']) -else: +if F_STRINGS_AVAILABLE: def line2pathd(node_dict): return f"M{node_dict['x1']} {node_dict['y1']}L{node_dict['x2']} {node_dict['y2']}" +else: + def line2pathd(node_dict): + return "M{} {}L{} {}".format(node_dict['x1'], node_dict['y1'], node_dict['x2'], node_dict['y2']) parser_dict = {