Fix ImportError with lxml==5.2.1 (Cython 3.0)#243
Merged
Conversation
Agent-Logs-Url: https://github.com/lasp/space_packet_parser/sessions/7c56f61f-469d-40ba-abd9-96a2e2a1e2c2 Co-authored-by: medley56 <7018964+medley56@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix import error with lxml version 5.2.1
Fix ImportError with lxml==5.2.1 (Cython 3.0)
Mar 27, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #243 +/- ##
=======================================
Coverage 94.81% 94.82%
=======================================
Files 48 48
Lines 3861 3868 +7
=======================================
+ Hits 3661 3668 +7
Misses 200 200 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes import-time failures when using lxml==5.2.1 (Cython 3), where lxml.etree.ElementTree/Element are compiled as Cython functions, breaking |-style union annotations and isinstance() checks.
Changes:
- Added
from __future__ import annotationsto defer type annotation evaluation in affected modules. - Updated
validate_xtce()to useElementTree._ElementTreeforisinstance()checks (works across supportedlxmlversions). - Removed now-redundant quoted return type annotations (e.g.,
-> "ParameterType").
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| space_packet_parser/common.py | Defers annotations to avoid import-time evaluation issues involving lxml element types; removes redundant quoted annotations. |
| space_packet_parser/xtce/calibrators.py | Defers annotations and removes redundant quoted annotations in from_xml return types. |
| space_packet_parser/xtce/comparisons.py | Defers annotations and removes redundant quoted annotations in from_xml return types. |
| space_packet_parser/xtce/encodings.py | Defers annotations and removes redundant quoted annotations in from_xml return types. |
| space_packet_parser/xtce/parameter_types.py | Defers annotations and removes redundant quoted annotations in from_xml return types. |
| space_packet_parser/xtce/parameters.py | Defers annotations and removes redundant quoted annotations in from_xml return types. |
| space_packet_parser/xtce/validation.py | Fixes isinstance() against ElementTree._ElementTree to avoid TypeError under lxml==5.2.1. |
medley56
approved these changes
Mar 31, 2026
medley56
added a commit
that referenced
this pull request
Mar 31, 2026
* Initial plan * Fix import error with lxml==5.2.1 (Cython 3.0) Agent-Logs-Url: https://github.com/lasp/space_packet_parser/sessions/7c56f61f-469d-40ba-abd9-96a2e2a1e2c2 Co-authored-by: medley56 <7018964+medley56@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: medley56 <7018964+medley56@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In lxml 5.2.1 (Cython 3.0.10),
lxml.etree.ElementTreeandlxml.etree.Elementare compiled as Cython functions rather than Python classes. This breaks two things at import time: the|union type annotation syntax (e.g.ElementTree.ElementTree | None) andisinstance()checks using those names.Changes
from __future__ import annotationsadded to all affected modules (common.py,xtce/calibrators.py,xtce/comparisons.py,xtce/encodings.py,xtce/parameter_types.py,xtce/parameters.py,xtce/validation.py). This defers annotation evaluation to strings, so the|operator is never called on a Cython function at module load time.isinstance()fix inxtce/validation.py: replacedisinstance(xml_source, ElementTree.ElementTree)withisinstance(xml_source, ElementTree._ElementTree)._ElementTreeis the actual underlying class (available across all supported lxml versions);ElementTree.ElementTreeis a Cython function in 5.2.1 and cannot be used as anisinstancetarget.Removed redundant quoted annotations (e.g.
-> "Calibrator") that became unnecessary oncefrom __future__ import annotationswas added.Summary
Fixes a
TypeErroron import when usinglxml==5.2.1caused by Cython 3.0 changinglxml.etree.ElementTreefrom a class to a Cython function. The fix usesfrom __future__ import annotationsto avoid runtime evaluation of type annotations, and switches the oneisinstance()check to use the concrete_ElementTreeclass.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
www.w3.org/usr/bin/python python -m pytest tests/unit/test_xtce/test_validation.py -v --no-header(dns block)/usr/bin/python python -m pytest tests/unit/ -x -q --no-header k/_temp/ghcca-node/node/bin/git(dns block)/usr/bin/python python -m pytest tests/integration/ -x -q --no-header ndor/bin/git(dns block)If you need me to access, download, or install something from one of these locations, you can either:
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.