def __new__(cls, *args, **kwargs):
target_cls = None
fallback_cls = None
- if 'type' in kwargs:
- for subcls in cls._all_subclasses():
- if getattr(subcls, 'type', '') is None:
- fallback_cls = subcls
- if getattr(subcls, 'type', None) == kwargs['type']:
- target_cls = subcls
- break
+ for subcls in cls._all_subclasses():
+ if getattr(subcls, 'type', '') is None:
+ fallback_cls = subcls
+ if getattr(subcls, 'type', None) == kwargs.get('type', None):
+ target_cls = subcls
+ break
if target_cls is None and fallback_cls is not None and issubclass(fallback_cls, cls):
target_cls = fallback_cls
retval = object.__new__(target_cls or cls)
import pytest
-from fints.formals import Container, ContainerField, DataElementField, DataElementGroupField, DigitsField, NumericField, Field, SegmentSequence, SegmentHeader, AlphanumericField
+from fints.formals import Container, ContainerField, DataElementField, DataElementGroupField, DigitsField, NumericField, Field, SegmentSequence, SegmentHeader, AlphanumericField, GenericGroupField
def test_container_simple():
class A(Container):
h = SegmentHeader('HNHBS', 5, 1)
assert repr(h) == "fints.formals.SegmentHeader('HNHBS', 5, 1)"
+
+def test_container_generic():
+ class A(Container):
+ a = DataElementGroupField()
+
+ assert isinstance(A._fields['a'], GenericGroupField)
+
+ i1 = A()
+ assert i1._fields['a'].type is None
+
+ assert i1.a
+
+ i2 = A(a=[])