Skip to content

refactor(python): add ty suppression codes to existing type: ignores#4639

Merged
dbrattli merged 1 commit into
mainfrom
refactor/py-ty-suppression-codes
Jun 9, 2026
Merged

refactor(python): add ty suppression codes to existing type: ignores#4639
dbrattli merged 1 commit into
mainfrom
refactor/py-ty-suppression-codes

Conversation

@dbrattli

@dbrattli dbrattli commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Five library lines carry intentional # type: ignore[<code>] comments for Pyright — genuine, accepted typing gaps:

  • int32.div_rem// / % on a deliberately weak SupportsInt bound (# type: ignore[operator])
  • StringableBase.__str__/__repr__ — duck-typed self.ToString() provided by subclasses (# type: ignore[attr-defined])
  • FSharpArray.append — intentional LSP-incompatible override of MutableSequence.append (# type: ignore[override])
  • async_.parallelmap(...) arg-type (# type: ignore[arg-type])

ty does not honour mypy/pyright rule codes, so it re-reported all of these. This appends ty-prefixed suppressions as a separate trailing comment:

q = x // y  # type: ignore[operator]  # ty: ignore[unsupported-operator]

Why the separate-comment form

Folding the ty code into the same bracket — # type: ignore[operator, ty:unsupported-operator]breaks Pyright's bracket parser (the : invalidates the whole comment) and de-suppresses the line. With two comments, Pyright reads its [...] bracket and ty reads # ty: ignore[...]. Verified against Pyright 1.1.407 and latest with the repo's reportUnnecessaryTypeIgnoreComment: true config.

Verification

ty (lib) ty (tests) Pyright (lib) Pyright (tests) runtime
before 68 118 0 34 2350 ✓
after 61 118 0 34 2350 ✓

Silences 7 false/intentional ty diagnostics with no change to Pyright and all 2350 Python tests passing. (Counts are relative to current main, i.e. after #4637 and #4638.)

Context

Part of an investigation into whether ty could eventually replace Pyright for this repo. Together with #4638 (FSharpRef overloads, −178) this brings ty from 364 → 179 total diagnostics. The remainder are genuine ty solver limitations (Option/SomeWrapper typevar widening, bidirectional generic specialization) best left until ty matures.

🤖 Generated with Claude Code

Five library lines carry intentional `# type: ignore[<code>]` comments
for Pyright (genuine, accepted gaps: a too-weak `SupportsInt` bound on
div_rem, the StringableBase duck-typed ToString, an intentional
FSharpArray.append LSP override, and an async map arg-type). Astral's
`ty` does not honour mypy/pyright rule codes, so it re-reported all of
them.

Append ty-prefixed suppressions as a separate trailing comment, e.g.

    q = x // y  # type: ignore[operator]  # ty: ignore[unsupported-operator]

The separate-comment form is required: folding the ty code into the
same bracket (`# type: ignore[operator, ty:unsupported-operator]`)
breaks Pyright's bracket parser and de-suppresses the line. With two
comments, Pyright reads its bracket and ty reads `# ty: ignore[...]`.

Silences 7 false/intentional `ty` diagnostics (library 68 -> 61) with
no change to Pyright (0 library / 34 tests) and all 2350 Python tests
passing.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Python Type Checking Results (Pyright)

Metric Value
Total errors 34
Files with errors 4
Excluded files 4
New errors ✅ No
Excluded files with errors (4 files)

These files have known type errors and are excluded from CI. Remove from pyrightconfig.ci.json as errors are fixed.

File Errors Status
temp/tests/Python/test_hash_set.py 18 Excluded
temp/tests/Python/test_applicative.py 12 Excluded
temp/tests/Python/test_nested_and_recursive_pattern.py 2 Excluded
temp/tests/Python/fable_modules/thoth_json_python/encode.py 2 Excluded

@dbrattli dbrattli merged commit 700ef78 into main Jun 9, 2026
32 checks passed
@dbrattli dbrattli deleted the refactor/py-ty-suppression-codes branch June 9, 2026 22:06
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