(cls, pool: Pool)
| 704 | |
| 705 | @classmethod |
| 706 | def checkout(cls, pool: Pool) -> _ConnectionFairy: |
| 707 | if TYPE_CHECKING: |
| 708 | rec = cast(_ConnectionRecord, pool._do_get()) |
| 709 | else: |
| 710 | rec = pool._do_get() |
| 711 | |
| 712 | try: |
| 713 | dbapi_connection = rec.get_connection() |
| 714 | except BaseException as err: |
| 715 | with util.safe_reraise(): |
| 716 | rec._checkin_failed(err, _fairy_was_created=False) |
| 717 | |
| 718 | # not reached, for code linters only |
| 719 | raise |
| 720 | |
| 721 | echo = pool._should_log_debug() |
| 722 | fairy = _ConnectionFairy(pool, dbapi_connection, rec, echo) |
| 723 | |
| 724 | rec.fairy_ref = ref = weakref.ref( |
| 725 | fairy, |
| 726 | lambda ref: ( |
| 727 | _finalize_fairy( |
| 728 | None, rec, pool, ref, echo, transaction_was_reset=False |
| 729 | ) |
| 730 | if _finalize_fairy is not None |
| 731 | else None |
| 732 | ), |
| 733 | ) |
| 734 | _strong_ref_connection_records[ref] = rec |
| 735 | if echo: |
| 736 | pool.logger.debug( |
| 737 | "Connection %r checked out from pool", dbapi_connection |
| 738 | ) |
| 739 | return fairy |
| 740 | |
| 741 | def _checkin_failed( |
| 742 | self, err: BaseException, _fairy_was_created: bool = True |
no test coverage detected