(
self,
state: InstanceState[Any],
dict_: _InstanceDict,
value: Any,
initiator: Optional[AttributeEventToken] = None,
passive: PassiveFlag = PassiveFlag.PASSIVE_OFF,
check_old: Any = None,
pop: bool = False,
_adapt: bool = True,
)
| 1942 | pass |
| 1943 | |
| 1944 | def set( |
| 1945 | self, |
| 1946 | state: InstanceState[Any], |
| 1947 | dict_: _InstanceDict, |
| 1948 | value: Any, |
| 1949 | initiator: Optional[AttributeEventToken] = None, |
| 1950 | passive: PassiveFlag = PassiveFlag.PASSIVE_OFF, |
| 1951 | check_old: Any = None, |
| 1952 | pop: bool = False, |
| 1953 | _adapt: bool = True, |
| 1954 | ) -> None: |
| 1955 | |
| 1956 | if value is DONT_SET: |
| 1957 | return |
| 1958 | |
| 1959 | iterable = orig_iterable = value |
| 1960 | new_keys = None |
| 1961 | |
| 1962 | # pulling a new collection first so that an adaptation exception does |
| 1963 | # not trigger a lazy load of the old collection. |
| 1964 | new_collection, user_data = self._initialize_collection(state) |
| 1965 | if _adapt: |
| 1966 | setting_type = util.duck_type_collection(iterable) |
| 1967 | receiving_type = self._duck_typed_as |
| 1968 | |
| 1969 | if setting_type is not receiving_type: |
| 1970 | given = ( |
| 1971 | "None" if iterable is None else iterable.__class__.__name__ |
| 1972 | ) |
| 1973 | wanted = ( |
| 1974 | "None" |
| 1975 | if self._duck_typed_as is None |
| 1976 | else self._duck_typed_as.__name__ |
| 1977 | ) |
| 1978 | raise TypeError( |
| 1979 | "Incompatible collection type: %s is not %s-like" |
| 1980 | % (given, wanted) |
| 1981 | ) |
| 1982 | |
| 1983 | # If the object is an adapted collection, return the (iterable) |
| 1984 | # adapter. |
| 1985 | if hasattr(iterable, "_sa_iterator"): |
| 1986 | iterable = iterable._sa_iterator() |
| 1987 | elif setting_type is dict: |
| 1988 | new_keys = list(iterable) |
| 1989 | iterable = iterable.values() |
| 1990 | else: |
| 1991 | iterable = iter(iterable) |
| 1992 | elif util.duck_type_collection(iterable) is dict: |
| 1993 | new_keys = list(value) |
| 1994 | |
| 1995 | new_values = list(iterable) |
| 1996 | |
| 1997 | evt = self._bulk_replace_token |
| 1998 | |
| 1999 | self.dispatch.bulk_replace(state, new_values, evt, keys=new_keys) |
| 2000 | |
| 2001 | # propagate NO_RAISE in passive through to the get() for the |
nothing calls this directly
no test coverage detected