FreeOpcUa / opcua-asyncio

OPC UA library for python >= 3.7
GNU Lesser General Public License v3.0
1.04k stars 345 forks source link

VariantType and SecurityPolicyType should be IntEnum #1634

Closed dakotahorstman closed 2 months ago

dakotahorstman commented 2 months ago

Describe the bug
Attempts to serialize an object with SecurityPolicyType or VariantType attributes fail. Enums cannot be serialized. Changing them to IntEnum makes them serializable, plus they are already effectively IntEnums based on their implementation (i.e. named_attribute = int).

To Reproduce

import json
from asyncua.ua import VariantType, SecurityPolicyType

json.dumps({"variant": VariantType.Boolean, "security_policy": SecurityPolicyType.None})

>>> `TypeError: Object of type VariantType is not JSON serializable`
OR
>>> `TypeError: Object of type SecurityPolicyType is not JSON serializable`

Expected behavior
Serialization to succeed.

Version
Python-Version:3.12 opcua-asyncio Version (e.g. master branch, 0.9): 1.1.0