MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / _setup_table

Method _setup_table

lib/sqlalchemy/orm/decl_base.py:1724–1800  ·  view source on GitHub ↗
(self, table: Optional[FromClause] = None)

Source from the content-addressed store, hash-verified

1722 )
1723
1724 def _setup_table(self, table: Optional[FromClause] = None) -> None:
1725 cls = self.cls
1726 cls_as_Decl = cast("MappedClassProtocol[Any]", cls)
1727
1728 tablename = self.tablename
1729 table_args = self.table_args
1730 clsdict_view = self.clsdict_view
1731 declared_columns = self.declared_columns
1732 column_ordering = self.column_ordering
1733
1734 manager = attributes.manager_of_class(cls)
1735
1736 if (
1737 self.table_fn is None
1738 and "__table__" not in clsdict_view
1739 and table is None
1740 ):
1741 if hasattr(cls, "__table_cls__"):
1742 table_cls = cast(
1743 Type[Table],
1744 util.unbound_method_to_callable(cls.__table_cls__), # type: ignore # noqa: E501
1745 )
1746 else:
1747 table_cls = Table
1748
1749 if tablename is not None:
1750 args: Tuple[Any, ...] = ()
1751 table_kw: Dict[str, Any] = {}
1752
1753 if table_args:
1754 if isinstance(table_args, dict):
1755 table_kw = table_args
1756 elif isinstance(table_args, tuple):
1757 if isinstance(table_args[-1], dict):
1758 args, table_kw = table_args[0:-1], table_args[-1]
1759 else:
1760 args = table_args
1761
1762 autoload_with = clsdict_view.get("__autoload_with__")
1763 if autoload_with:
1764 table_kw["autoload_with"] = autoload_with
1765
1766 autoload = clsdict_view.get("__autoload__")
1767 if autoload:
1768 table_kw["autoload"] = True
1769
1770 sorted_columns = sorted(
1771 declared_columns,
1772 key=lambda c: column_ordering.get(c, 0),
1773 )
1774 table = self.set_cls_attribute(
1775 "__table__",
1776 table_cls(
1777 tablename,
1778 self._metadata_for_cls(manager),
1779 *sorted_columns,
1780 *args,
1781 **table_kw,

Callers 1

__init__Method · 0.95

Calls 6

_metadata_for_clsMethod · 0.95
castFunction · 0.85
manager_of_classMethod · 0.80
set_cls_attributeMethod · 0.80
getMethod · 0.45
contains_columnMethod · 0.45

Tested by

no test coverage detected