Skip to content

Resolve all ty diagnostics#14296

Open
him2him2 wants to merge 5 commits intosphinx-doc:masterfrom
him2him2:fix-ty-toml-typo
Open

Resolve all ty diagnostics#14296
him2him2 wants to merge 5 commits intosphinx-doc:masterfrom
him2him2:fix-ty-toml-typo

Conversation

@him2him2
Copy link

@him2him2 him2him2 commented Feb 11, 2026

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-subscriptablenot-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.pyunresolved-attribute
    • sphinx/util/docutils.pyunresolved-import
    • sphinx/util/parallel.pyunresolved-attribute
    • tests/test_builders/xpath_util.pyno-matching-overload (ty#117)
    • tests/test_intl/test_intl.pymissing-argument (ty#1787)
    • tests/test_transforms/test_transforms_post_transforms.pyinvalid-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.pyunsupported-operator (sorted → Sized)
    • sphinx/util/matching.pyno-matching-overload (filter + re.match)
    • tests/test_ext_intersphinx/test_ext_intersphinx.pynot-iterable
    • tests/test_util/test_util_inspect.pyinvalid-type-form
    • tests/test_util/test_util_typing.pyinvalid-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-subscriptablenot-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
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