Commit 8d83f126 authored by oroulet's avatar oroulet

Make sure no field is using keyword string

parent 4fb0d26b
......@@ -4,6 +4,7 @@ from datetime import datetime
import uuid
import logging
import re
import keyword
from typing import Union, List, TYPE_CHECKING, Tuple, Optional, Any
from dataclasses import dataclass, field
......@@ -108,13 +109,14 @@ def clean_name(name):
Remove characters that might be present in OPC UA structures
but cannot be part of of Python class names
"""
if keyword.iskeyword(name):
return name + "_"
if name.isidentifier():
return name
else:
newname = re.sub(r'\W+', '_', name)
newname = re.sub(r'^[0-9]+', r'_\g<0>', newname)
logger.warning("renamed %s to %s due to Python syntax", name, newname)
return newname
newname = re.sub(r'\W+', '_', name)
newname = re.sub(r'^[0-9]+', r'_\g<0>', newname)
logger.warning("renamed %s to %s due to Python syntax", name, newname)
return newname
def get_default_value(uatype, enums=None):
......
......@@ -1124,12 +1124,12 @@ async def test_duplicated_browsenames_different_ns(opc):
return
async def test_custom_enum(opc):
async def test_custom_enum_x(opc):
idx = 4
await new_enum(opc.opc, idx, "MyCustEnum", [
"titi",
"toto",
"tutu",
"None",
])
await opc.opc.load_data_type_definitions()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment