refactor(language): an operator, a declaration kind and a notation name the values they can be, rather than being a string - #345
Merged
Conversation
…me the values they can be, rather than being a string Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Hdxai54hc4LwxFQBqMM8jF
This was referenced Sep 1, 2026
This was referenced Sep 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
The following content was generated by AI.
Six vocabularies that were closed in prose but open in the annotation now name their members, so the checker enforces what a docstring used to ask for. No behaviour changes.
The one that earns its place:
Namespace.kind()returnedstr | Nonewith the four kinds written out in its docstring, and bothmatchstatements over it ended incase _. It now returnsDeclarationKind, the wildcards are gone, andnon-exhaustive-match— already an error since #325 — guards a fifth kind.kind() -> str | None-> DeclarationKind | Noneresolution.pyNamespace.dtypes: Mapping[str, str]Mapping[str, DeclaredDtype]resolution.py, threaded throughexclusivity.pyUnaryOperatorNode.op: strUnaryOperatorexpression_parser.pyBinaryOperatorNode.op: strBinaryOperatorexpression_parser.pyFormat.notation: ClassVar[str]ClassVar[Notation]format.py,latex.py,typst.pySymbolTable.notation: strNotationsymbols.py_PRECEDENCE,_PREDICATES,_ORDERED_DTYPESandNUMERIC_DTYPESare typed by the vocabulary they are keyed or filled by, which is what makes the narrowing reach a lookup rather than stop at the field.Verified:
pixi run ci— lint, 1003 tests,mkdocs build --strict, 27 documents compiled. Each new guard was checked by deleting it and watching the checker fail; output below.The guards, deleted
non-exhaustive-matchonkind— remove thecase 'lookup':arm from_resolve_where:DeclaredDtypeon_ORDERED_DTYPES— misspell'datetime':BinaryOperatoron the node — construct one the grammar cannot produce:Two shapes the checker forced, and one cast
The wildcards could not simply become
case None:. pyrefly 1.2.0 does not treat a wildcard-freematchover aLiteralas terminating flow, so removingcase _made the outerassert_never(node)unreachable-by-its-own-lights and errored.case _: assert_never(kind)does not fix it either — only a bareraisedoes, and a wildcard defeats the exhaustiveness check that was the point.The shape that gets both: hoist
kind = ns.kind(...), handleNoneas a guard clause above the match, and let the arms that only record an error fall out to one sharedreturn node. That reads as an invariant rather than a workaround — an arm that builds a node returns it, an error path returns the node unchanged, once.One cast was added, in
SymbolTable.load:notation not in NOTATIONSdoes not narrow astr, so the value crossing into the typed field is cast at the validation boundary, directly under the check that earns it.redundant-castis an error since #325 and does not flag it.Deliberately not done
OPERATOR_SPELLINGS/Format.operators/Walk.op— 30 rows, 46 call sites. Left for a follow-up, becausetests/typesetting/test_golden.py::test_the_golden_model_asks_for_every_operator_the_vocabulary_spellsalready catches an unspelled name, so it is a smaller win than the six above and wants its own diff.FORMATSandBUILTINS— keyed by strings arriving from argparse and from a parsed file. ALiteralkey buys a cast at the boundary and nothing downstream.EdgeNode.policy→Literal['wrap']— honest, but a one-memberLiteralis ceremony.getattr(vdef.bounds, side)inmodel.pyanddimensions.pyreturnsAny. A real hole, but the fix is reaching the two fields directly, not aLiteral.