Skip to content

Commit f8ece56

Browse files
chore: record the deliberate narrowing of __or__
`dict.__or__` is declared to return `dict`; these always return an `HclDict`, which mypy reads as an incompatible override. The ignore says which of the two it is.
1 parent 5557bfd commit f8ece56

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

hcl2/meta.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,13 @@ def __reduce__(self) -> Tuple[Any, ...]:
9595
"""Carry the metadata through pickling, which `dict` would not."""
9696
return (_rebuild, (dict(self), self.hcl_meta))
9797

98-
def __or__(self, other: Any) -> "HclDict":
98+
def __or__(self, other: Any) -> "HclDict": # type: ignore[override]
9999
"""Merge, keeping this side's metadata.
100100
101+
Narrower than `dict.__or__`, which is declared to return `dict` for any
102+
mapping: this always returns an `HclDict`, so the ignore records a
103+
deliberate narrowing rather than a mismatch.
104+
101105
`dict.__or__` returns a plain `dict`, so `body | {"size": ...}` -- the
102106
idiomatic non-mutating edit -- would drop the sidecar and the block
103107
would then be written as an object. `{**body, ...}` cannot be helped:
@@ -107,7 +111,7 @@ def __or__(self, other: Any) -> "HclDict":
107111
merged.update(other)
108112
return merged
109113

110-
def __ror__(self, other: Any) -> "HclDict":
114+
def __ror__(self, other: Any) -> "HclDict": # type: ignore[override]
111115
"""Same from the left, keeping this side's metadata."""
112116
merged = HclDict(other, meta=copy_module.copy(self.hcl_meta))
113117
merged.update(self)

0 commit comments

Comments
 (0)