diff --git a/xsdata/formats/dataclass/context.py b/xsdata/formats/dataclass/context.py index 9707400f..28e1d82e 100644 --- a/xsdata/formats/dataclass/context.py +++ b/xsdata/formats/dataclass/context.py @@ -132,13 +132,19 @@ def is_binding_model(self, clazz: type[T]) -> bool: if not self.class_type.is_model(clazz): return False - return not self.models_package or ( + has_valid_module = ( hasattr(clazz, "__module__") and isinstance(clazz.__module__, str) - and clazz.__module__.startswith(self.models_package) and clazz.__module__ in sys.modules ) + if not has_valid_module: + return False + + return not self.models_package or clazz.__module__.startswith( + self.models_package + ) + def find_types(self, qname: str) -> list[type[T]]: """Find all classes that match the given xsi:type qname.