MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / _get_comparator

Method _get_comparator

lib/sqlalchemy/ext/hybrid.py:1741–1771  ·  view source on GitHub ↗
(
        self, comparator: Any
    )

Source from the content-addressed store, hash-verified

1739 return self._get_comparator(_expr)
1740
1741 def _get_comparator(
1742 self, comparator: Any
1743 ) -> Callable[[Any], _HybridClassLevelAccessor[_T]]:
1744 proxy_attr = attributes._create_proxied_attribute(self)
1745
1746 def expr_comparator(
1747 owner: Type[object],
1748 ) -> _HybridClassLevelAccessor[_T]:
1749 # because this is the descriptor protocol, we don't really know
1750 # what our attribute name is. so search for it through the
1751 # MRO.
1752 for lookup in owner.__mro__:
1753 if self.__name__ in lookup.__dict__:
1754 if lookup.__dict__[self.__name__] is self:
1755 name = self.__name__
1756 break
1757 else:
1758 name = attributes._UNKNOWN_ATTR_KEY # type: ignore[assignment,unused-ignore] # noqa: E501
1759
1760 return cast(
1761 "_HybridClassLevelAccessor[_T]",
1762 proxy_attr(
1763 owner,
1764 name,
1765 self,
1766 comparator(owner),
1767 doc=comparator.__doc__ or self.__doc__,
1768 ),
1769 )
1770
1771 return expr_comparator
1772
1773
1774class Comparator(interfaces.PropComparator[_T]):

Callers 2

_expr_comparatorMethod · 0.95
_get_exprMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected