Commit ec93edf
authored
fix: make DataType.type return self instead of a clone (#7708)
annotate_types stored a deep clone of each DataType node in the node's
own _type slot via `self._set_type(e, e.copy())`. The .copy() existed
to avoid a self-cycle that would break recursive consumers of _type
(serde.dump, etc). But Expr.__deepcopy__ also recursively walked _type,
so every later e.copy() of an ancestor dragged the shadow type along.
The work compounded across nested STRUCT levels and turned annotate
into a >100s operation on wide, deeply nested STRUCT casts.
Conceptually, asking "what type is this DataType?" should answer "itself".
Special-case DataType in Expression.type the same way Cast already is,
via an is_data_type ClassVar:
- Expression.type returns self when self.is_data_type is True.
- DataType (and all its subclasses) set is_data_type = True.
- The DataType annotator becomes a no-op (no copy needed; no _type to set).
- serde.dump skips the TYPE field when node.type is node, since storing
a self-reference is meaningless and was the original reason the
annotator needed the .copy().
- _to_s uses node.is_data_type so DataType subclasses (IntervalSpan,
PseudoType, ObjectIdentifier) are skipped uniformly during repr.
Behavior change to call out: on a DataType `dt`, `dt.type is dt` is now
true (previously it returned a clone, equal but not identical). Equality
semantics are unchanged.1 parent 63608d6 commit ec93edf
4 files changed
Lines changed: 8 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
88 | 88 | | |
89 | 89 | | |
90 | 90 | | |
| 91 | + | |
91 | 92 | | |
92 | 93 | | |
93 | 94 | | |
| |||
962 | 963 | | |
963 | 964 | | |
964 | 965 | | |
| 966 | + | |
| 967 | + | |
965 | 968 | | |
966 | 969 | | |
967 | 970 | | |
| |||
2552 | 2555 | | |
2553 | 2556 | | |
2554 | 2557 | | |
2555 | | - | |
| 2558 | + | |
2556 | 2559 | | |
2557 | 2560 | | |
2558 | 2561 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
187 | 187 | | |
188 | 188 | | |
189 | 189 | | |
| 190 | + | |
| 191 | + | |
190 | 192 | | |
191 | 193 | | |
192 | 194 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
53 | | - | |
| 53 | + | |
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
335 | | - | |
| 335 | + | |
336 | 336 | | |
337 | 337 | | |
338 | 338 | | |
| |||
0 commit comments