(
self, lazy_collection: _LazyCollectionProtocol[_T]
)
| 938 | delattr(obj, self.target_collection) |
| 939 | |
| 940 | def _new( |
| 941 | self, lazy_collection: _LazyCollectionProtocol[_T] |
| 942 | ) -> Tuple[Type[Any], _T]: |
| 943 | creator = ( |
| 944 | self.parent.creator |
| 945 | if self.parent.creator is not None |
| 946 | else cast("_CreatorProtocol", self.target_class) |
| 947 | ) |
| 948 | collection_class = util.duck_type_collection(lazy_collection()) |
| 949 | |
| 950 | if collection_class is None: |
| 951 | raise exc.InvalidRequestError( |
| 952 | f"lazy collection factory did not return a " |
| 953 | f"valid collection type, got {collection_class}" |
| 954 | ) |
| 955 | if self.parent.proxy_factory: |
| 956 | return ( |
| 957 | collection_class, |
| 958 | self.parent.proxy_factory( |
| 959 | lazy_collection, creator, self.value_attr, self |
| 960 | ), |
| 961 | ) |
| 962 | |
| 963 | if self.parent.getset_factory: |
| 964 | getter, setter = self.parent.getset_factory(collection_class, self) |
| 965 | else: |
| 966 | getter, setter = self.parent._default_getset(collection_class) |
| 967 | |
| 968 | if collection_class is list: |
| 969 | return ( |
| 970 | collection_class, |
| 971 | cast( |
| 972 | _T, |
| 973 | _AssociationList( |
| 974 | lazy_collection, creator, getter, setter, self |
| 975 | ), |
| 976 | ), |
| 977 | ) |
| 978 | elif collection_class is dict: |
| 979 | return ( |
| 980 | collection_class, |
| 981 | cast( |
| 982 | _T, |
| 983 | _AssociationDict( |
| 984 | lazy_collection, creator, getter, setter, self |
| 985 | ), |
| 986 | ), |
| 987 | ) |
| 988 | elif collection_class is set: |
| 989 | return ( |
| 990 | collection_class, |
| 991 | cast( |
| 992 | _T, |
| 993 | _AssociationSet( |
| 994 | lazy_collection, creator, getter, setter, self |
| 995 | ), |
| 996 | ), |
| 997 | ) |
no test coverage detected