Remove an item by value, consulting the keyfunc for the key.
(
self,
value: _KT,
_sa_initiator: Union[AttributeEventToken, Literal[None, False]] = None,
)
| 475 | @collection.remover # type: ignore[untyped-decorator] |
| 476 | @collection.internally_instrumented # type: ignore[untyped-decorator] |
| 477 | def remove( |
| 478 | self, |
| 479 | value: _KT, |
| 480 | _sa_initiator: Union[AttributeEventToken, Literal[None, False]] = None, |
| 481 | ) -> None: |
| 482 | """Remove an item by value, consulting the keyfunc for the key.""" |
| 483 | |
| 484 | key = self.keyfunc(value) |
| 485 | |
| 486 | if key is base.NO_VALUE: |
| 487 | if not self.ignore_unpopulated_attribute: |
| 488 | self._raise_for_unpopulated( |
| 489 | value, _sa_initiator, warn_only=False |
| 490 | ) |
| 491 | return |
| 492 | elif key is Missing: |
| 493 | if not self.ignore_unpopulated_attribute: |
| 494 | self._raise_for_unpopulated( |
| 495 | value, _sa_initiator, warn_only=True |
| 496 | ) |
| 497 | key = None |
| 498 | else: |
| 499 | return |
| 500 | |
| 501 | # Let self[key] raise if key is not in this collection |
| 502 | # testlib.pragma exempt:__ne__ |
| 503 | if self[key] != value: |
| 504 | raise sa_exc.InvalidRequestError( |
| 505 | "Can not remove '%s': collection holds '%s' for key '%s'. " |
| 506 | "Possible cause: is the KeyFuncDict key function " |
| 507 | "based on mutable properties or properties that only obtain " |
| 508 | "values after flush?" % (value, self[key], key) |
| 509 | ) |
| 510 | self.__delitem__(key, _sa_initiator) # type: ignore[call-arg] |
| 511 | |
| 512 | |
| 513 | def _mapped_collection_cls( |
nothing calls this directly
no test coverage detected