feat(classgen): add support for unknown types
This commit is contained in:
@@ -30,6 +30,7 @@ Note: This module assumes the presence of other modules and classes such as `Cla
|
||||
"""
|
||||
|
||||
import dataclasses
|
||||
import inspect
|
||||
from dataclasses import dataclass, fields, is_dataclass
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
@@ -261,6 +262,10 @@ def construct_value(
|
||||
|
||||
return t(field_value) # type: ignore
|
||||
|
||||
if inspect.isclass(t) and t.__name__ == "Unknown":
|
||||
# Return the field value as is
|
||||
return field_value
|
||||
|
||||
msg = f"Unhandled field type {t} with value {field_value}"
|
||||
raise ClanError(msg)
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import copy
|
||||
import dataclasses
|
||||
import inspect
|
||||
import pathlib
|
||||
from dataclasses import MISSING
|
||||
from enum import EnumType
|
||||
@@ -110,6 +111,12 @@ def type_to_dict(
|
||||
if t is None:
|
||||
return {"type": "null"}
|
||||
|
||||
if inspect.isclass(t) and t.__name__ == "Unknown":
|
||||
# Empty should represent unknown
|
||||
# We don't know anything about this type
|
||||
# Nor about the nested fields, if there are any
|
||||
return {}
|
||||
|
||||
if dataclasses.is_dataclass(t):
|
||||
fields = dataclasses.fields(t)
|
||||
properties = {}
|
||||
|
||||
Reference in New Issue
Block a user