(
self, class_: Any, obj: Any
)
| 495 | return self._as_instance(class_, obj) |
| 496 | |
| 497 | def _as_instance( |
| 498 | self, class_: Any, obj: Any |
| 499 | ) -> AssociationProxyInstance[_T]: |
| 500 | try: |
| 501 | inst = class_.__dict__[self.key + "_inst"] |
| 502 | except KeyError: |
| 503 | inst = None |
| 504 | |
| 505 | # avoid exception context |
| 506 | if inst is None: |
| 507 | owner = self._calc_owner(class_) |
| 508 | if owner is not None: |
| 509 | inst = AssociationProxyInstance.for_proxy(self, owner, obj) |
| 510 | setattr(class_, self.key + "_inst", inst) |
| 511 | else: |
| 512 | inst = None |
| 513 | |
| 514 | if inst is not None and not inst._is_canonical: |
| 515 | # the AssociationProxyInstance can't be generalized |
| 516 | # since the proxied attribute is not on the targeted |
| 517 | # class, only on subclasses of it, which might be |
| 518 | # different. only return for the specific |
| 519 | # object's current value |
| 520 | return inst._non_canonical_get_for_object(obj) # type: ignore |
| 521 | else: |
| 522 | return inst # type: ignore # TODO |
| 523 | |
| 524 | def _calc_owner(self, target_cls: Any) -> Any: |
| 525 | # we might be getting invoked for a subclass |
no test coverage detected