Skip to content

Modernize type annotations (PEP 585/604) - #5

Merged
thorwhalen merged 2 commits into
mainfrom
claude/modernize-type-annotations
Aug 10, 2026
Merged

Modernize type annotations (PEP 585/604)#5
thorwhalen merged 2 commits into
mainfrom
claude/modernize-type-annotations

Conversation

@thorwhalen

Copy link
Copy Markdown
Member

What

The package declares requires-python = ">=3.10", so the legacy typing spellings are no longer needed:

  • Optional[X]X | None
  • Dict/Tuple/List[...]dict/tuple/list[...]
  • typing.Callable / typing.Iteratorcollections.abc equivalents

Two defects fixed along the way

  • js_parse.replace_ids_in_code was annotated -> (str, dict) — a tuple of types, not a type. Now -> tuple[str, dict].
  • find_and_replace_ids imported Union, which was never used.

Verification

  • pytest: 3 passed.
  • All modules import, including the opt-in jy.ts_parse (tree-sitter).
  • Every touched signature was introspected with inspect.signature. This matters: X | None in a signature is evaluated eagerly at def-time, so on <3.10 it would raise TypeError rather than fail silently. It evaluates cleanly.
  • compileall clean.

No behaviour change.

Formatting

Deliberately not reformatted. The same 3 files already fail black on master, so that drift is pre-existing and belongs to CI's format step, not to this diff.

Provenance

This started as uncommitted work in a local worktree that had fallen 8 commits behind master, overlapping the same three files. Rather than force a conflicted merge, the transformation was re-derived against current master (which had since reformatted to double quotes), and extended to cover the remaining occurrences so the package is now consistent.

https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU

The package requires Python >=3.10, so the legacy typing generics and
Optional[...] unions are no longer needed:

- Optional[X] -> X | None
- Dict/Tuple/List[...] -> dict/tuple/list[...]
- typing.Callable / typing.Iterator -> collections.abc equivalents

Also fixes two defects found while doing this:

- js_parse.replace_ids_in_code was annotated `-> (str, dict)`, a tuple
  *of types* rather than a type. Now `-> tuple[str, dict]`.
- find_and_replace_ids imported `Union`, which was never used.

No behaviour change. Verified all modules still import and that every
touched signature evaluates at runtime (X | None is evaluated eagerly in
annotations, so this would fail loudly on <3.10).

Formatting is left alone: the same 3 files already fail black on master,
so that drift is pre-existing and is CI's job, not this change's.

Claude-Session: https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU
Joins the existing exploratory notebooks under misc/. Checked for
credentials and machine-local paths before committing; none present.

Claude-Session: https://claude.ai/code/session_01EwmvrvgLNjzgE8weA4MMWU
@thorwhalen
thorwhalen merged commit c1ce1fb into main Aug 10, 2026
12 checks passed
@thorwhalen
thorwhalen deleted the claude/modernize-type-annotations branch August 10, 2026 09:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant