A :class:`_expression.ColumnCollection` that maintains deduplicating behavior. This is useful by schema level objects such as :class:`_schema.Table` and :class:`.PrimaryKeyConstraint`. The collection includes more sophisticated mutator methods as well to suit schema objects which
| 2025 | |
| 2026 | |
| 2027 | class DedupeColumnCollection(ColumnCollection[str, _NAMEDCOL]): |
| 2028 | """A :class:`_expression.ColumnCollection` |
| 2029 | that maintains deduplicating behavior. |
| 2030 | |
| 2031 | This is useful by schema level objects such as :class:`_schema.Table` and |
| 2032 | :class:`.PrimaryKeyConstraint`. The collection includes more |
| 2033 | sophisticated mutator methods as well to suit schema objects which |
| 2034 | require mutable column collections. |
| 2035 | |
| 2036 | .. versionadded:: 1.4 |
| 2037 | |
| 2038 | """ |
| 2039 | |
| 2040 | def add( # type: ignore[override] |
| 2041 | self, column: _NAMEDCOL, key: Optional[str] = None |
| 2042 | ) -> None: |
| 2043 | if key is not None and column.key != key: |
| 2044 | raise exc.ArgumentError( |
| 2045 | "DedupeColumnCollection requires columns be under " |
| 2046 | "the same key as their .key" |
| 2047 | ) |
| 2048 | key = column.key |
| 2049 | |
| 2050 | if key is None: |
| 2051 | raise exc.ArgumentError( |
| 2052 | "Can't add unnamed column to column collection" |
| 2053 | ) |
| 2054 | |
| 2055 | if key in self._index: |
| 2056 | existing = self._index[key][1] |
| 2057 | |
| 2058 | if existing is column: |
| 2059 | return |
| 2060 | |
| 2061 | self.replace(column) |
| 2062 | |
| 2063 | # pop out memoized proxy_set as this |
| 2064 | # operation may very well be occurring |
| 2065 | # in a _make_proxy operation |
| 2066 | util.memoized_property.reset(column, "proxy_set") |
| 2067 | else: |
| 2068 | self._append_new_column(key, column) |
| 2069 | |
| 2070 | def _append_new_column(self, key: str, named_column: _NAMEDCOL) -> None: |
| 2071 | l = len(self._collection) |
| 2072 | self._collection.append( |
| 2073 | (key, named_column, _ColumnMetrics(self, named_column)) |
| 2074 | ) |
| 2075 | self._colset.add(named_column._deannotate()) |
| 2076 | self._index[l] = (key, named_column) |
| 2077 | self._index[key] = (key, named_column) |
| 2078 | |
| 2079 | def _populate_separate_keys( |
| 2080 | self, iter_: Iterable[Tuple[str, _NAMEDCOL]] |
| 2081 | ) -> None: |
| 2082 | """populate from an iterator of (key, column)""" |
| 2083 | cols = list(iter_) |
| 2084 |
no outgoing calls