(
class_: Type[_O],
key: str,
uselist: bool = False,
callable_: Optional[_LoaderCallable] = None,
useobject: bool = False,
impl_class: Optional[Type[_AttributeImpl]] = None,
backref: Optional[str] = None,
**kw: Any,
)
| 2620 | |
| 2621 | |
| 2622 | def _register_attribute_impl( |
| 2623 | class_: Type[_O], |
| 2624 | key: str, |
| 2625 | uselist: bool = False, |
| 2626 | callable_: Optional[_LoaderCallable] = None, |
| 2627 | useobject: bool = False, |
| 2628 | impl_class: Optional[Type[_AttributeImpl]] = None, |
| 2629 | backref: Optional[str] = None, |
| 2630 | **kw: Any, |
| 2631 | ) -> QueryableAttribute[Any]: |
| 2632 | manager = manager_of_class(class_) |
| 2633 | if uselist: |
| 2634 | factory = kw.pop("typecallable", None) |
| 2635 | typecallable = manager.instrument_collection_class( |
| 2636 | key, factory or list |
| 2637 | ) |
| 2638 | else: |
| 2639 | typecallable = kw.pop("typecallable", None) |
| 2640 | |
| 2641 | dispatch = cast( |
| 2642 | "_Dispatch[QueryableAttribute[Any]]", manager[key].dispatch |
| 2643 | ) # noqa: E501 |
| 2644 | |
| 2645 | impl: _AttributeImpl |
| 2646 | |
| 2647 | if impl_class: |
| 2648 | # TODO: this appears to be the WriteOnlyAttributeImpl / |
| 2649 | # DynamicAttributeImpl constructor which is hardcoded |
| 2650 | impl = cast("Type[_WriteOnlyAttributeImpl]", impl_class)( |
| 2651 | class_, key, dispatch, **kw |
| 2652 | ) |
| 2653 | elif uselist: |
| 2654 | impl = _CollectionAttributeImpl( |
| 2655 | class_, key, callable_, dispatch, typecallable=typecallable, **kw |
| 2656 | ) |
| 2657 | elif useobject: |
| 2658 | impl = _ScalarObjectAttributeImpl( |
| 2659 | class_, key, callable_, dispatch, **kw |
| 2660 | ) |
| 2661 | else: |
| 2662 | impl = _ScalarAttributeImpl(class_, key, callable_, dispatch, **kw) |
| 2663 | |
| 2664 | manager[key].impl = impl |
| 2665 | |
| 2666 | if backref: |
| 2667 | _backref_listeners(manager[key], backref, uselist) |
| 2668 | |
| 2669 | manager.post_configure_attribute(key) |
| 2670 | return manager[key] |
| 2671 | |
| 2672 | |
| 2673 | def _register_descriptor( |
no test coverage detected