scanny / python-pptx

Create Open XML PowerPoint documents in Python
MIT License
2.35k stars 510 forks source link

Let Shapes and SlidePlaceholders fulfill the Mapping interface #800

Open timhoffm opened 2 years ago

timhoffm commented 2 years ago

Both are essentially mappings and define the minimal interface for collections.abc.Mapping (https://docs.python.org/3/library/collections.abc.html#collections-abstract-base-classes), i.e. __iter__, __getitem__ and __len__.

By inheriting from Mapping we mix in the full mapping behavior, .e.g. .get() and .key() methods. This is to make these collections feel more pythonic. Additionally, it's a real usability improvement: e.g. for SlidePlaceholders one cannot guess the valid keys, which makes placeholders[idx] difficult to use. Having placeholders.keys() available makes inspection much easier.