Skip to content

Resolve all ty diagnostics - #14296

Closed
him2him2 wants to merge 6 commits into
sphinx-doc:masterfrom
him2him2:fix-ty-toml-typo
Closed

him2him2 wants to merge 6 commits into
sphinx-doc:masterfrom
him2him2:fix-ty-toml-typo

Conversation

@him2him2

@him2him2 him2him2 commented Feb 11, 2026 •

Copy link
Copy Markdown
Contributor

Summary

The ty CI check currently reports 312 diagnostics, causing every PR to
show a failing check. This PR resolves all of them:

  1. Fix typo in ty.toml (non-subscriptable → not-subscriptable)
    so the existing suppression rule takes effect (-16 diagnostics).

  2. Suppress unused-type-ignore-comment in ty.toml. These
    # type: ignore comments are required by mypy; ty should not warn
    about them (-288 diagnostics).

  3. Remove six stale # ty: ignore directives for issues that ty
    has since fixed (-6 diagnostics):

    • sphinx/builders/xml.py — unresolved-attribute
    • sphinx/util/docutils.py — unresolved-import
    • sphinx/util/parallel.py — unresolved-attribute
    • tests/test_builders/xpath_util.py — no-matching-overload (ty#117)
    • tests/test_intl/test_intl.py — missing-argument (ty#1787)
    • tests/test_transforms/test_transforms_post_transforms.py — invalid-return-type
  4. Add targeted # ty: ignore for five false positives caused by
    ty inference limitations (+5 inline suppressions, -5 diagnostics):

    • sphinx/ext/apidoc/_generate.py — unsupported-operator (sorted → Sized)
    • sphinx/util/matching.py — no-matching-overload (filter + re.match)
    • tests/test_ext_intersphinx/test_ext_intersphinx.py — not-iterable
    • tests/test_util/test_util_inspect.py — invalid-type-form
    • tests/test_util/test_util_typing.py — invalid-type-form (×2)

Net result: 312 → 0 diagnostics.

Ref: #14238

Test plan

  • The ty CI check passes with zero diagnostics
  • All other lint checks remain green

The rule name ``non-subscriptable`` is not recognised by ty,
so the intended suppression has no effect.  This causes 15
``not-subscriptable`` errors and 1 ``unknown-rule`` warning
in every CI run (cf. sphinx-doc#14238).
@him2him2 him2him2 changed the title Fix typo in ty.toml: non-subscriptable → not-subscriptable Resolve all ty diagnostics Feb 11, 2026
- Suppress ``unused-type-ignore-comment`` in ty.toml; these
  ``# type: ignore`` comments are needed by mypy.
- Remove six stale ``# ty: ignore`` directives for issues that
  ty has since fixed.
- Add targeted ``# ty: ignore`` comments for five false positives
  that stem from ty inference limitations.

Together with the previous commit, this brings the ty diagnostic
count from 312 to 0.

Ref: sphinx-doc#14238
Python 3.15 added ``_check_help()`` to ``argparse.ArgumentParser``
which calls ``re.sub()`` during ``add_argument()``.  The C
implementation of ``re.sub()`` requires actual ``str`` objects, so it
rejects ``_TranslationProxy`` with ``TypeError``.

Fix by inheriting from ``str``:

- ``str.__new__`` stores the untranslated message as the base buffer
- All dunder methods still delegate to the *translated* text
- C-level operations see a valid ``str`` and succeed
- Replace ``__getstate__``/``__setstate__``/``__copy__`` with
  ``__reduce__`` (the standard mechanism for ``str`` subclasses)
- Suppress FURB189 (no viable UserString alternative for C-level checks)
- Fix PYI034: return `Self` from `__new__` instead of concrete class
- Fix ARG004: prefix unused `__new__` params with `_`
- Fix mypy overrides: widen `__contains__` to `object`, `__getitem__`
  to `SupportsIndex | slice` to satisfy Liskov substitution
- Remove stale `type: ignore[return-value]` (now a `str` subclass)
- Collapse `__new__` to one line and match parameter names with `__init__` (pyright)
- Suppress ruff ARG004 for `__new__` (params needed to match `__init__` for pyright)
- Accept `object` in `__contains__` to satisfy LSP (mypy override check) with
  isinstance guard for type narrowing
- Revert `__contains__` char type for ty/mypy compatibility

@m-aciek m-aciek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me 👍

@m-aciek

m-aciek commented May 28, 2026 •

Copy link
Copy Markdown
Contributor

@him2him2 do you remember which ty version were you running this against? There's also #14239 run against earlier ty 0.0.9.

@m-aciek

m-aciek commented May 28, 2026

Copy link
Copy Markdown
Contributor

For reference another cleaning PR: #14328.

@jdillard

jdillard commented Aug 11, 2026 •

Copy link
Copy Markdown
Member

Thanks for taking the time to do this, but I am closing this as superseded by #14538.

If we update ty in the future, and I say "if" because there is talk of switching to pyrefly, it might just be better to start with a fresh PR.

@jdillard jdillard closed this Aug 11, 2026
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Sep 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants