chore: fix type checking issues#700
Conversation
| if TYPE_CHECKING: | ||
| assert section is None or isinstance(section, type_) |
There was a problem hiding this comment.
This could be made a runtime check but this way, we ensure the exact same runtime behaviour as before.
| msg = f"Could not find soname in {fn}" | ||
| raise ValueError(msg) | ||
| needed.extend(t.needed for t in section.iter_tags() if t.entry.d_tag == "DT_NEEDED") | ||
| needed.extend(t.needed for t in section.iter_tags() if t.entry.d_tag == "DT_NEEDED") # type: ignore[attr-defined] |
There was a problem hiding this comment.
All the # type: ignore[attr-defined] are for dynamically defined attributes
There was a problem hiding this comment.
Pull request overview
This PR updates auditwheel’s code and integration tests to satisfy mypy when used with newer pyelftools versions that ship richer type hints.
Changes:
- Add explicit
DynamicSection/ segment type narrowing (isinstance(...)) where.dynamicsections and PT_* segments are accessed. - Add targeted
# type: ignore[attr-defined]annotations forpyelftoolstag attributes not represented in stubs. - Update the pre-commit mypy hook environment to use
pyelftools>=0.33.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
tests/integration/test_manylinux.py |
Narrows .dynamic section type for mypy and ignores an attribute not present in stubs. |
tests/integration/test_android.py |
Narrows .dynamic section type for mypy before iterating dynamic tags. |
src/auditwheel/lddtree.py |
Narrows segment types (InterpSegment, DynamicSegment) and ignores tag attributes missing from stubs. |
src/auditwheel/elfutils.py |
Adds a typed helper for section lookup and narrows section types for mypy. |
.pre-commit-config.yaml |
Ensures mypy runs against a pyelftools version that includes the new typing hints. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #700 +/- ##
==========================================
+ Coverage 95.73% 95.74% +0.01%
==========================================
Files 23 23
Lines 1923 1928 +5
Branches 362 361 -1
==========================================
+ Hits 1841 1846 +5
Misses 46 46
Partials 36 36 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
pyelftools recently released a version with typing hints.
auditwheel fails to pass mypy checks with this new version.
This PR aims to fix (or ignore) mypy reported issues.