"""Helper functions for working with PPTX files with the `python-pptx` library.""" def remove_shape(shape) -> None: """Remove a shape from a slide. This is as of May 2024 the official workaround for removing shapes from a slide in PPTX files using the `python-pptx` library, as there is no direct method to remove a shape from a slide. See: https://stackoverflow.com/q/63308405 Args: shape: Shape to remove. """ sp = shape._element # noqa sp.getparent().remove(sp) def remove_slide(source, index: int): """Remove a slide from a presentation. This is as of May 2024 the official workaround for removing slides from a PPTX file using the `python-pptx` library, as there is no direct method to remove a slide from a presentation. See: https://stackoverflow.com/q/54945022 Args: source: Presentation object. index: 0-based index of the slide to remove. """ xml_slides = source.slides._sldIdLst # noqa slides = list(xml_slides) xml_slides.remove(slides[index])