Skip to content

Commit 866012b

Browse files
antonsyndclaude
andcommitted
docs(spec,oracle): null_coalescing_assignment.md dictionary examples use nullable element types with status notes for the missing-key and expression forms (#1790); oracle ledger mirrors the membership-needle deviation
- null_coalescing_assignment.md §Dictionary Operations used non-nullable element types (SPY0222 at dff55b2, 852bf48 and e3b4345 alike — correctly, per its own §Type Requirements); corrected to `Data | None` / `int | None`. A subscript store on a MISSING key raises KeyError at every sha, and `(name ??= "Default")` / `(a ??= (b ??= 42))` are SPY0104 (statement-only parser) at every sha: the contract sentences stay (Rule 7 — spec is authoritative) with status notes pointing at #1790, where the owner rules between implementing them and rewording. Executed with `sharpyc run` @ e3b4345. - build_tools/cpython_oracle/ledger.yaml: `python3 -m build_tools.cpython_oracle ledger --write` after 02beba0 added `membership-needle-type-mismatch` to docs/deviations.yaml — the ledger mirrors the catalog; no other change. All four /push regeneration gates are clean at this state (check_spy_staleness.sh 0, check_spy_tests_staleness.sh 0, stdlib docs and ledger no further diff). Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01G7JYB3Yguom773bhAACicS
1 parent e3b4345 commit 866012b

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

build_tools/cpython_oracle/ledger.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,14 @@ deviations:
349349
spec_ref: docs/stdlib/math.md
350350
existing_diagnostic: null
351351
planned_diagnostic: null
352+
- id: membership-needle-type-mismatch
353+
category: operators
354+
audience: python
355+
severity: error
356+
code: SPY0222
357+
spec_ref: docs/language_specification/membership_operators.md#needle-type
358+
existing_diagnostic: SPY0222
359+
planned_diagnostic: null
352360
- id: min-max-mixed-numeric-promotion
353361
category: stdlib
354362
audience: python

docs/language_specification/null_coalescing_assignment.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,25 @@ class DataManager:
5757

5858
## Dictionary Operations
5959

60+
> **Status (#1790):** the element type must be nullable or Optional (see [Type Requirements](#type-requirements)), and today a subscript store on a *missing* key raises `KeyError` before the coalesce — the missing-key behaviour below is the intended semantics, not yet the implemented one.
61+
6062
```python
61-
cache: dict[str, Data] = {}
63+
cache: dict[str, Data | None] = {}
6264

6365
def get_or_create(key: str) -> Data:
6466
# Compute only if key is missing or maps to None
6567
cache[key] ??= compute_expensive_data(key)
6668
return cache[key]
6769

6870
# Works with dictionary subscript
69-
settings: dict[str, int] = {}
71+
settings: dict[str, int | None] = {}
7072
settings["timeout"] ??= 30 # Set default if not present
7173
```
7274

7375
## Return Value
7476

77+
> **Status (#1790):** `??=` is a statement today — the expression forms below are `SPY0104` until the expression form is ruled and implemented.
78+
7579
The `??=` operator returns the final value (either existing or newly assigned):
7680

7781
```python

0 commit comments

Comments
 (0)