Skip to content

cyclonedds-python fails to import with Python 3.14 #318

@owenjklan

Description

@owenjklan

My employer needs to update one of our products to be delivered on Fedora 43. Fedora 43 uses Python 3.14 as the default python version.

When attempting to import from cyclonedds in unit tests, or even a normal REPL, the following traceback occurs:

13:33:52  test_dds.py:1: in <module>
13:33:52      from cyclonedds.idl import IdlStruct
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/__init__.py:13: in <module>
13:33:52      from . import internal, util, qos, core, domain, topic, pub, sub, builtin, dynamic, idl, qos_provider
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/pub.py:22: in <module>
13:33:52      from .builtin_types import DcpsEndpoint, endpoint_constructor, cqos_to_qos
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/builtin_types.py:22: in <module>
13:33:52      from cyclonedds.idl._typesupport.DDS.XTypes import TypeIdentifier
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/_typesupport/DDS/__init__.py:8: in <module>
13:33:52      from . import XTypes
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/_typesupport/DDS/XTypes/__init__.py:9: in <module>
13:33:52      from ._ddsi_xt_type_object import ANNOTATION_OCTETSEC_VALUE_MAX_LEN, ANNOTATION_STR_VALUE_MAX_LEN, AliasMemberFlag, AliasTypeFlag, AnnotationParameterFlag, AnnotationParameterValue, AnnotationTypeFlag, AppliedAnnotation, AppliedAnnotationParameter, AppliedAnnotationParameterSeq, AppliedAnnotationSeq, AppliedBuiltinMemberAnnotations, AppliedBuiltinTypeAnnotations, AppliedVerbatimAnnotation, BitBound, BitflagFlag, BitmaskTypeFlag, BitsetMemberFlag, BitsetTypeFlag, CollectionElementFlag, CollectionTypeFlag, CommonAliasBody, CommonAnnotationParameter, CommonArrayHeader, CommonBitfield, CommonBitflag, CommonBitmaskHeader, CommonCollectionElement, CommonCollectionHeader, CommonDiscriminatorMember, CommonEnumeratedHeader, CommonEnumeratedLiteral, CommonStructMember, CommonUnionMember, CompleteAliasBody, CompleteAliasHeader, CompleteAliasType, CompleteAnnotationHeader, CompleteAnnotationParameter, CompleteAnnotationParameterSeq, CompleteAnnotationType, CompleteArrayHeader, CompleteArrayType, CompleteBitfield, CompleteBitfieldSeq, CompleteBitflag, CompleteBitflagSeq, CompleteBitmaskHeader, CompleteBitmaskType, CompleteBitsetHeader, CompleteBitsetType, CompleteCollectionElement, CompleteCollectionHeader, CompleteDiscriminatorMember, CompleteElementDetail, CompleteEnumeratedHeader, CompleteEnumeratedLiteral, CompleteEnumeratedLiteralSeq, CompleteEnumeratedType, CompleteExtendedType, CompleteMapType, CompleteMemberDetail, CompleteSequenceType, CompleteStructHeader, CompleteStructMember, CompleteStructMemberSeq, CompleteStructType, CompleteTypeDetail, CompleteTypeObject, CompleteUnionHeader, CompleteUnionMember, CompleteUnionMemberSeq, CompleteUnionType, EK_BOTH, EK_COMPLETE, EK_MINIMAL, EnumTypeFlag, EnumeratedLiteralFlag, EquivalenceHash, EquivalenceKind, ExtendedAnnotationParameterValue, ExtendedTypeDefn, INVALID_LBOUND, INVALID_SBOUND, LBound, LBoundSeq, MEMBER_NAME_MAX_LENGTH, MemberFlag, MemberFlagMinimalMask, MemberId, MemberName, MinimalAliasBody, MinimalAliasHeader, MinimalAliasType, MinimalAnnotationHeader, MinimalAnnotationParameter, MinimalAnnotationParameterSeq, MinimalAnnotationType, MinimalArrayHeader, MinimalArrayType, MinimalBitfield, MinimalBitfieldSeq, MinimalBitflag, MinimalBitflagSeq, MinimalBitmaskHeader, MinimalBitmaskType, MinimalBitsetHeader, MinimalBitsetType, MinimalCollectionElement, MinimalCollectionHeader, MinimalDiscriminatorMember, MinimalEnumeratedHeader, MinimalEnumeratedLiteral, MinimalEnumeratedLiteralSeq, MinimalEnumeratedType, MinimalExtendedType, MinimalMapType, MinimalMemberDetail, MinimalSequenceType, MinimalStructHeader, MinimalStructMember, MinimalStructMemberSeq, MinimalStructType, MinimalTypeDetail, MinimalTypeObject, MinimalUnionHeader, MinimalUnionMember, MinimalUnionMemberSeq, MinimalUnionType, NameHash, PlainArrayLElemDefn, PlainArraySElemDefn, PlainCollectionHeader, PlainMapLTypeDefn, PlainMapSTypeDefn, PlainSequenceLElemDefn, PlainSequenceSElemDefn, PrimitiveTypeId, QualifiedTypeName, SBound, SBoundSeq, StringLTypeDefn, StringSTypeDefn, StronglyConnectedComponent, StronglyConnectedComponentId, StructMemberFlag, StructTypeFlag, TI_PLAIN_ARRAY_LARGE, TI_PLAIN_ARRAY_SMALL, TI_PLAIN_MAP_LARGE, TI_PLAIN_MAP_SMALL, TI_PLAIN_SEQUENCE_LARGE, TI_PLAIN_SEQUENCE_SMALL, TI_STRING16_LARGE, TI_STRING16_SMALL, TI_STRING8_LARGE, TI_STRING8_SMALL, TI_STRONGLY_CONNECTED_COMPONENT, TK_ALIAS, TK_ANNOTATION, TK_ARRAY, TK_BITMASK, TK_BITSET, TK_BOOLEAN, TK_BYTE, TK_CHAR16, TK_CHAR8, TK_ENUM, TK_FLOAT128, TK_FLOAT32, TK_FLOAT64, TK_INT16, TK_INT32, TK_INT64, TK_INT8, TK_MAP, TK_NONE, TK_SEQUENCE, TK_STRING16, TK_STRING8, TK_STRUCTURE, TK_UINT16, TK_UINT32, TK_UINT64, TK_UINT8, TK_UNION, TYPE_NAME_MAX_LENGTH, TypeFlag, TypeFlagMinimalMask, TypeIdentfierWithSizeSeq, TypeIdentiferKind, TypeIdentifier, TypeIdentifierPair, TypeIdentifierPairSeq, TypeIdentifierSeq, TypeIdentifierTypeObjectPair, TypeIdentifierTypeObjectPairSeq, TypeIdentifierWithDependencies, TypeIdentifierWithDependenciesSeq, TypeIdentifierWithSize, TypeInformation, TypeInformationSeq, TypeKind, TypeObject, TypeObjectHashId, TypeObjectSeq, UnionCaseLabelSeq, UnionDiscriminatorFlag, UnionMemberFlag, UnionTypeFlag
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/_typesupport/DDS/XTypes/_ddsi_xt_type_object.py:88: in <module>
13:33:52      class MemberFlag(idl.IdlBitmask, typename="DDS.XTypes.MemberFlag"):
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/_typesupport/DDS/XTypes/_ddsi_xt_type_object.py:90: in MemberFlag
13:33:52      annotate.position("TRY_CONSTRUCT1", 0)
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/annotations.py:56: in position
13:33:52      __field_annotate(apply_to, "position", value)
13:33:52  /usr/lib64/python3.14/site-packages/cyclonedds/idl/annotations.py:37: in __field_annotate
13:33:52      raise TypeError(f"Member {pfield} is not defined.")
13:33:52  E   TypeError: Member TRY_CONSTRUCT1 is not defined.

The best I've been able to work out is that this might have something to do with a change to annotations in Python 3.14, but I don't understand metaclasses nearly enough to be sure of this.

I managed to "fix" the import issue by patching __field_annotate so that rather than raise a TypeError if pfield isn't found, then it adds the field to the annotations, assuming a type of bool.

Although this does allow the package to be imported, I'm not confident in my change, especially regarding possibilities of __field_annotate being used in a way I haven't considered / found. I also don't like that I'm making an assumption about the type to be applied to the annotations.

Hopefully somebody more familiar with the mechanics of the IdlBitmask, IdlBitmaskMeta and MemberFlag classes can provide a more robust fix for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions