Skip to content

Second approach to typing#165

Open
Suor wants to merge 27 commits intomasterfrom
new-typing
Open

Second approach to typing#165
Suor wants to merge 27 commits intomasterfrom
new-typing

Conversation

@Suor
Copy link
Owner

@Suor Suor commented Feb 28, 2026

  • started from simpler stuff not decorators, that one is hard
  • numerous type tests, very straightforward, even if silly sometimes
  • added pyih special language and generation
  • try to preserve as much as possible but fall back to Any if cannot

Use Claude Code + Opus 4.6 a lot. Sonnet just doesn't get it ;)

Suor and others added 27 commits February 26, 2026 11:04
ty cannot understand some literal collections types, i.e. `{'a': 1}`
being `dict[str, int]`, so we say it. Same for lambdas even typed with
`Callable[...]` and some builtins.
- simply more tests
- add type tests coverage check
- Separate type stubs docs into CLAUDE_TYPES.md for progressive discovery
- Replace GEMINI.md with symlink to CLAUDE.md
- Fix PYIH.md naming (pyi higher) and remove resolved FIX comments
- Add XPred variant type tests for select_keys, select_values, split_keys, some
- Document ty TypeVar unification bug with proper XFAIL markers
- Refactor type_tests/run.py: extract validate_file(), find_stale_xfails()
- Refactor translate_pyih.py: extract extract_xfunc_skip(), remove .copy()
- Add RES comments for translate_pyih string-vs-AST refactoring (too large)
- Add split_keys to extended_fns.rst function list

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Hashable correctly constrains is_distinct's element/key types since
the implementation uses sets internally, requiring hashable values.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- select now uses XPred for list/set/frozenset, Callable for dict/Mapping
- Added MutableMapping overloads to select, select_keys, select_values
- Added type tests for new overloads including MutableMapping

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
walk with Mapping/MutableMapping input returns dict. Added typed
pair-function overloads and corresponding type tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Existing XFunc overloads already handle pairs correctly via TypeVar
inference. Added tests to verify and removed resolved FIX comment.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…values

walk_keys/walk_values now support MutableMapping (returning dict) and
collection-of-pairs (list/set/frozenset of tuples, preserving type).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
compact now has specific overloads for list/set/frozenset, dict,
MutableMapping, and Mapping, with a catch-all fallback.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
flip/project/omit now support MutableMapping. flip also supports
collections of pairs (list/set/frozenset of tuples).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Both functions now accept list/set/frozenset of tuples with full
XPred expansion, in addition to dict/MutableMapping/Mapping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Also add coverage command reference to CLAUDE.md.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The .pyih translator tests parse PEP 695 type parameter syntax which
requires Python 3.12+.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This simplifies all catch-all overloads from `Callable[..., Any] | _Func`
to just `_XFunc`, since the two were always used together.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Ensures dict/MutableMapping/Mapping types are preserved when using
extended function predicates with select, matching the pattern used
by walk.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The Callable parameter now correctly requires list[_W] matching the
dict values type _W, catching mismatches. Added tests for same type,
wider (Iterable), and wrong type.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
compact(list[int | None]) now returns list[int], compact(dict[str, int |
None])
returns dict[str, int], etc. Only applies to invariant types (dict,
MutableMapping, list, tuple, set, frozenset) — covariant types like
Sequence would swallow non-None inputs via subtyping.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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