Skip to content

Commit dcd8048

Browse files
Copilotmedley56
andcommitted
Fix ImportError with lxml==5.2.1 (Cython 3.0) (#243)
* 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>
1 parent 5748945 commit dcd8048

7 files changed

Lines changed: 37 additions & 19 deletions

File tree

space_packet_parser/common.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Common mixins"""
22

3+
from __future__ import annotations
4+
35
import inspect
46
import logging
57
import warnings
@@ -154,7 +156,7 @@ def from_xml(
154156
parameter_lookup: dict[str, any] | None,
155157
parameter_type_lookup: dict[str, any] | None,
156158
container_lookup: dict[str, any] | None,
157-
) -> "XmlObject":
159+
) -> XmlObject:
158160
"""Create an object from an XML element
159161
160162
Notes
@@ -202,7 +204,7 @@ def to_xml(self, *, elmaker: ElementMaker) -> ElementTree.Element:
202204
class Parseable(Protocol):
203205
"""Defines an object that can be parsed from packet data."""
204206

205-
def parse(self, packet: "SpacePacket") -> None:
207+
def parse(self, packet: SpacePacket) -> None:
206208
"""Parse this entry from the packet data and add the necessary items to the packet."""
207209

208210

space_packet_parser/xtce/calibrators.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Calibrator definitions"""
22

3+
from __future__ import annotations
4+
35
from abc import ABCMeta, abstractmethod
46
from collections import namedtuple
57

@@ -23,7 +25,7 @@ def from_xml(
2325
parameter_lookup: dict[str, any] | None = None,
2426
parameter_type_lookup: dict[str, any] | None = None,
2527
container_lookup: dict[str, any] | None = None,
26-
) -> "Calibrator":
28+
) -> Calibrator:
2729
"""Abstract classmethod to create a default_calibrator object from an XML element.
2830
2931
Parameters
@@ -100,7 +102,7 @@ def from_xml(
100102
parameter_lookup: dict[str, any] | None = None,
101103
parameter_type_lookup: dict[str, any] | None = None,
102104
container_lookup: dict[str, any] | None = None,
103-
) -> "SplineCalibrator":
105+
) -> SplineCalibrator:
104106
"""Create a spline default_calibrator object from an <xtce:SplineCalibrator> XML element.
105107
106108
Parameters
@@ -270,7 +272,7 @@ def from_xml(
270272
parameter_lookup: dict[str, any] | None = None,
271273
parameter_type_lookup: dict[str, any] | None = None,
272274
container_lookup: dict[str, any] | None = None,
273-
) -> "PolynomialCalibrator":
275+
) -> PolynomialCalibrator:
274276
"""Create a polynomial default_calibrator object from an <xtce:PolynomialCalibrator> XML element.
275277
276278
Parameters
@@ -352,7 +354,7 @@ def from_xml(
352354
parameter_lookup: dict[str, any] | None = None,
353355
parameter_type_lookup: dict[str, any] | None = None,
354356
container_lookup: dict[str, any] | None = None,
355-
) -> "MathOperationCalibrator":
357+
) -> MathOperationCalibrator:
356358
"""Create a math operation default_calibrator from an <xtce:MathOperationCalibrator> XML element.
357359
358360
Parameters
@@ -456,7 +458,7 @@ def from_xml(
456458
parameter_lookup: dict[str, any] | None = None,
457459
parameter_type_lookup: dict[str, any] | None = None,
458460
container_lookup: dict[str, any] | None = None,
459-
) -> "ContextCalibrator":
461+
) -> ContextCalibrator:
460462
"""Create a ContextCalibrator object from an <xtce:ContextCalibrator> XML element
461463
462464
Parameters

space_packet_parser/xtce/comparisons.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Matching logical objects"""
22

3+
from __future__ import annotations
4+
35
from abc import ABCMeta, abstractmethod
46
from collections import namedtuple
57
from typing import Any
@@ -111,7 +113,7 @@ def from_xml(
111113
parameter_lookup: dict[str, any] | None = None,
112114
parameter_type_lookup: dict[str, any] | None = None,
113115
container_lookup: dict[str, any] | None = None,
114-
) -> "Comparison":
116+
) -> Comparison:
115117
"""Create
116118
117119
Parameters
@@ -301,7 +303,7 @@ def from_xml(
301303
parameter_lookup: dict[str, any] | None = None,
302304
parameter_type_lookup: dict[str, any] | None = None,
303305
container_lookup: dict[str, any] | None = None,
304-
) -> "Condition":
306+
) -> Condition:
305307
"""Classmethod to create a Condition object from an XML element.
306308
307309
Parameters
@@ -448,7 +450,7 @@ def from_xml(
448450
parameter_lookup: dict[str, any] | None = None,
449451
parameter_type_lookup: dict[str, any] | None = None,
450452
container_lookup: dict[str, any] | None = None,
451-
) -> "BooleanExpression":
453+
) -> BooleanExpression:
452454
"""Abstract classmethod to create a match criteria object from an XML element.
453455
454456
Parameters
@@ -615,7 +617,7 @@ def from_xml(
615617
parameter_lookup: dict[str, any] | None = None,
616618
parameter_type_lookup: dict[str, any] | None = None,
617619
container_lookup: dict[str, any] | None = None,
618-
) -> "DiscreteLookup":
620+
) -> DiscreteLookup:
619621
"""Create a DiscreteLookup object from an <xtce:DiscreteLookup> XML element
620622
621623
Parameters

space_packet_parser/xtce/encodings.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""DataEncoding definitions"""
22

3+
from __future__ import annotations
4+
35
import logging
46
import struct
57
import warnings
@@ -378,7 +380,7 @@ def from_xml(
378380
parameter_lookup: dict[str, any] | None = None,
379381
parameter_type_lookup: dict[str, any] | None = None,
380382
container_lookup: dict[str, any] | None = None,
381-
) -> "StringDataEncoding":
383+
) -> StringDataEncoding:
382384
"""Create a data encoding object from an <xtce:StringDataEncoding> XML element.
383385
384386
Notes
@@ -724,7 +726,7 @@ def from_xml(
724726
parameter_lookup: dict[str, any] | None = None,
725727
parameter_type_lookup: dict[str, any] | None = None,
726728
container_lookup: dict[str, any] | None = None,
727-
) -> "IntegerDataEncoding":
729+
) -> IntegerDataEncoding:
728730
"""Create a data encoding object from an <xtce:IntegerDataEncoding> XML element.
729731
730732
Parameters
@@ -891,7 +893,7 @@ def from_xml(
891893
parameter_lookup: dict[str, any] | None = None,
892894
parameter_type_lookup: dict[str, any] | None = None,
893895
container_lookup: dict[str, any] | None = None,
894-
) -> "FloatDataEncoding":
896+
) -> FloatDataEncoding:
895897
"""Create a data encoding object from an <xtce:FloatDataEncoding> XML element.
896898
897899
Parameters
@@ -1029,7 +1031,7 @@ def from_xml(
10291031
parameter_lookup: dict[str, any] | None = None,
10301032
parameter_type_lookup: dict[str, any] | None = None,
10311033
container_lookup: dict[str, any] | None = None,
1032-
) -> "BinaryDataEncoding":
1034+
) -> BinaryDataEncoding:
10331035
"""Create a data encoding object from an <xtce:BinaryDataEncoding> XML element.
10341036
10351037
Parameters

space_packet_parser/xtce/parameter_types.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""Parameter type objects"""
22

3+
from __future__ import annotations
4+
35
import warnings
46
from abc import ABCMeta
57

@@ -48,7 +50,7 @@ def from_xml(
4850
parameter_lookup: dict | None = None,
4951
parameter_type_lookup: dict | None = None,
5052
container_lookup: dict[str, any] | None = None,
51-
) -> "ParameterType":
53+
) -> ParameterType:
5254
"""Create a *ParameterType* from an <xtce:ParameterType> XML element.
5355
5456
Parameters
@@ -241,7 +243,7 @@ def from_xml(
241243
parameter_lookup: dict[str, any] | None = None,
242244
parameter_type_lookup: dict[str, any] | None = None,
243245
container_lookup: dict[str, any] | None = None,
244-
) -> "EnumeratedParameterType":
246+
) -> EnumeratedParameterType:
245247
"""Create an EnumeratedParameterType from an <xtce:EnumeratedParameterType> XML element.
246248
Overrides ParameterType.from_parameter_type_xml_element
247249

space_packet_parser/xtce/parameters.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""ParameterType definitions"""
22

3+
from __future__ import annotations
4+
35
from dataclasses import dataclass
46

57
import lxml.etree as ElementTree
@@ -47,7 +49,7 @@ def from_xml(
4749
tree: ElementTree.ElementTree | None = None,
4850
parameter_lookup: dict[str, any] | None = None,
4951
container_lookup: dict[str, any] | None = None,
50-
) -> "Parameter":
52+
) -> Parameter:
5153
"""Create a Parameter object from an XML element.
5254
5355
Parameters

space_packet_parser/xtce/validation.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""XTCE document validation classes and utilities."""
22

3+
from __future__ import annotations
4+
35
import hashlib
46
import logging
57
import os
@@ -534,7 +536,11 @@ def validate_xtce(
534536

535537
# Parse XML document into a tree object
536538
try:
537-
if isinstance(xml_source, ElementTree.ElementTree):
539+
# In lxml >= 5.2.1 (Cython 3.0), ElementTree.ElementTree is a Cython function
540+
# rather than a class, which makes isinstance() fail with a TypeError.
541+
# ElementTree._ElementTree is the actual underlying class and is available in all
542+
# supported lxml versions.
543+
if isinstance(xml_source, ElementTree._ElementTree):
538544
xml_tree = xml_source
539545
elif isinstance(xml_source, Path):
540546
xml_tree = ElementTree.parse(str(xml_source))

0 commit comments

Comments
 (0)