Repository navigation
refactor(pptx): use python-pptx shape types instead of getattr/hasattr - #4712
PeterStaar-IBM merged 1 commit into
Conversation
_get_shape_position read top/left with getattr(shape, attr). It now types the shape as BaseShape and reads shape.top or shape.left directly. The AttributeError catch stays, with a comment: python-pptx wraps an element without a registered class, such as a p:contentPart inside a group, in a plain BaseShape whose getters raise it. The text check used hasattr(shape, "text"). Only autoshape.Shape and its placeholder subclasses define text, so it is now an isinstance check. No output change. Signed-off-by: Daniel Nguyen <danielnguyenh07@gmail.com>
|
✅ DCO Check Passed Thanks @DanielNg0729, all your commits are properly signed off. 🎉 |
Merge Protections🟢 Merge protection satisfied — ready to merge. Show 1 satisfied protection🟢 Enforce conventional commitMake sure that we follow https://www.conventionalcommits.org/en/v1.0.0/
|
AI triage (advisory)Checked commit This PR refactors the PPTX backend to replace Topic labels added: CI safety: no concern found. A maintainer must still approve CI. 1 related pull request(s) in the same code
The |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
AI first review (advisory): no blocking issue found
This review covers the full diff at a53b2066c1. It read the code only. It did not run tests or code from this pull request.
The PR replaces getattr(shape, attr) in _get_shape_position with direct shape.top / shape.left access. It types the shape helpers with BaseShape and Literal["top", "left"], and it replaces hasattr(shape, "text") in handle_shapes with isinstance(shape, Shape). I found no wrong behavior. from __future__ import annotations keeps BaseShape out of runtime evaluation, so the guarded pptx import stays safe. Shape is used at runtime only after the constructor confirms that pptx is available. Limits: I did not run the tests or ty. I could not confirm from the workspace that text exists only on autoshape.Shape and its placeholder subclasses, because the python-pptx source is not installed here. The main remaining risk is a merge conflict with open PR #4443, which changes the same hunks.
A maintainer makes the merge decision. This review never approves the pull request.
Summary
_get_shape_positionread the position withgetattr(shape, attr). It now typesshapeasBaseShapeandattrasLiteral["top", "left"], and readsshape.toporshape.leftdirectly._iter_shapes_by_positionnow usesBaseShapeinstead ofobject.AttributeErrorcatch in_get_shape_positionstays, with a comment. python-pptx wraps an element without a registered class, such as ap:contentPartinside a group, in a plainBaseShape. Itstopandleftgetters then raiseAttributeError.handle_shapescheckedhasattr(shape, "text"). In python-pptx, onlyautoshape.Shapeand its placeholder subclasses definetext, so the check is nowisinstance(shape, Shape).The behaviour does not change, so I did not add a test.
Checklist: