# Buggy code
def read_svg(
    filename: str,
    quantization: float,
    simplify: bool = False,
    return_size: bool = False,
) -> Union["LineCollection", Tuple["LineCollection", float, float]]:
    """Read a SVG file an return its content as a :class:`LineCollection` instance.

    All curved geometries are chopped in segments no longer than the value of *quantization*.
    Optionally, the geometries are simplified using Shapely, using the value of *quantization*
    as tolerance.

    Args:
        filename: path of the SVG file
        quantization: maximum size of segment used to approximate curved geometries
        simplify: run Shapely's simplify on loaded geometry
        return_size: if True, return a size 3 Tuple containing the geometries and the SVG
            width and height

    Returns:
        imported geometries, and optionally width and height of the SVG
    """

    doc = svg.Document(filename)
    width, height, scale_x, scale_y, offset_x, offset_y = _calculate_page_size(doc.root)
    lc = _convert_flattened_paths(
        doc.flatten_all_paths(),
        quantization,
        scale_x,
        scale_y,
        offset_x,
        offset_y,
        simplify,
    )

    if return_size:
        if width is None or height is None:
            _, _, width, height = lc.bounds() or 0, 0, 0, 0
        return lc, width, height
    else:
        return lc


# Traceback (IndexError)
Traceback (most recent call last):
File "/Users/theuser/.pyenv/versions/plotter/bin/vpype", line 8, in <module>
sys.exit(cli())
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 72, in main
return super().main(args=preprocess_argument_list(args), **extra)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 1290, in invoke
return _process_result(rv)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 1224, in _process_result
value = ctx.invoke(self.result_callback, value, **ctx.params)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 118, in process_pipeline
execute_processors(processors)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/cli.py", line 202, in execute_processors
state = proc(state)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype/decorators.py", line 154, in global_processor
state.vector_data = f(state.vector_data, *args, **kwargs)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype_cli/read.py", line 106, in read
read_svg(file, quantization=quantization, simplify=not no_simplify),
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/vpype/io.py", line 163, in read_svg
doc.flatten_all_paths(), quantization, scale_x, scale_y, offset_x, offset_y, simplify,
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/document.py", line 219, in flatten_all_paths
path_filter, path_conversions)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/document.py", line 142, in flatten_all_paths
path = transform(parse_path(converter(path_elem)), path_tf)
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/parser.py", line 91, in parse_path
segments.closed = True
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2241, in closed
if value and not self._is_closable():
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2219, in _is_closable
end = self[-1].end
File "/Users/theuser/.pyenv/versions/3.7.7/envs/plotter/lib/python3.7/site-packages/svgpathtools/path.py", line 2081, in __getitem__
return self._segments[index]
IndexError: list index out of range

# Fixed code
def read_svg(
    filename: str,
    quantization: float,
    simplify: bool = False,
    return_size: bool = False,
) -> Union["LineCollection", Tuple["LineCollection", float, float]]:
    """Read a SVG file an return its content as a :class:`LineCollection` instance.

    All curved geometries are chopped in segments no longer than the value of *quantization*.
    Optionally, the geometries are simplified using Shapely, using the value of *quantization*
    as tolerance.

    Args:
        filename: path of the SVG file
        quantization: maximum size of segment used to approximate curved geometries
        simplify: run Shapely's simplify on loaded geometry
        return_size: if True, return a size 3 Tuple containing the geometries and the SVG
            width and height

    Returns:
        imported geometries, and optionally width and height of the SVG
    """

    doc = svg.Document(filename)
    width, height, scale_x, scale_y, offset_x, offset_y = _calculate_page_size(doc.root)
    lc = _convert_flattened_paths(
        doc.paths(),
        quantization,
        scale_x,
        scale_y,
        offset_x,
        offset_y,
        simplify,
    )

    if return_size:
        if width is None or height is None:
            _, _, width, height = lc.bounds() or 0, 0, 0, 0
        return lc, width, height
    else:
        return lc