Skip & Log properties with 'None' as default value

This commit is contained in:
Raffson 2022-10-09 15:28:36 +02:00
parent 2be3257e3c
commit bcac6c4287
No known key found for this signature in database
GPG Key ID: B0402B2C9B764D99

View File

@ -1,6 +1,7 @@
from __future__ import annotations
import inspect
import logging
from collections.abc import Iterator
from dataclasses import dataclass
from typing import Any, Generic, Type, TypeVar
@ -33,6 +34,11 @@ class UnitProperty(Generic[ValueT]):
for name, attr in inspect.getmembers(props, inspect.isclass):
if name.startswith("__"):
continue
attr_values = getattr(attr, "Values", None)
if attr_values is None and unit_type.property_defaults[name] is None:
msg = f"Skipping property '{name}' for '{unit_type.id}': default value is None."
logging.warning(msg)
continue
yield cls.property_from(attr, unit_type.property_defaults[name])
@classmethod