From 449436859f86d0094f6d7448ee2fbb4cac2a1ed4 Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Tue, 9 Jun 2026 23:55:11 +0200 Subject: [PATCH] refactor(python): add ty suppression codes to existing type: ignores Five library lines carry intentional `# type: ignore[]` 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) --- src/fable-library-py/fable_library/async_.py | 2 +- src/fable-library-py/fable_library/bases.py | 4 ++-- src/fable-library-py/fable_library/core/array.pyi | 2 +- src/fable-library-py/fable_library/int32.py | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fable-library-py/fable_library/async_.py b/src/fable-library-py/fable_library/async_.py index e33a223db2..7e6437f36e 100644 --- a/src/fable-library-py/fable_library/async_.py +++ b/src/fable-library-py/fable_library/async_.py @@ -104,7 +104,7 @@ def binder(_: Any | Unit = UNIT) -> Async[None]: def parallel[T](computations: IEnumerable_1[Async[T]]) -> Async[Array[T]]: def delayed() -> Async[Array[T]]: - tasks: Iterable[Awaitable[T]] = map(start_as_task, computations) # type: ignore[arg-type] + tasks: Iterable[Awaitable[T]] = map(start_as_task, computations) # type: ignore[arg-type] # ty: ignore[invalid-assignment, invalid-argument-type] all: Future[list[T]] = asyncio.gather(*tasks) def to_array(results: list[T]) -> Async[Array[T]]: diff --git a/src/fable-library-py/fable_library/bases.py b/src/fable-library-py/fable_library/bases.py index c15237c978..fadae5cb2a 100644 --- a/src/fable-library-py/fable_library/bases.py +++ b/src/fable-library-py/fable_library/bases.py @@ -71,10 +71,10 @@ class StringableBase: __slots__ = () def __str__(self) -> str: - return self.ToString() # type: ignore[attr-defined] + return self.ToString() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute] def __repr__(self) -> str: - return self.ToString() # type: ignore[attr-defined] + return self.ToString() # type: ignore[attr-defined] # ty: ignore[unresolved-attribute] class EquatableBase(ABC): diff --git a/src/fable-library-py/fable_library/core/array.pyi b/src/fable-library-py/fable_library/core/array.pyi index a501f34824..b4d0d5ecef 100644 --- a/src/fable-library-py/fable_library/core/array.pyi +++ b/src/fable-library-py/fable_library/core/array.pyi @@ -74,7 +74,7 @@ class FSharpArray[T](MutableSequence[T]): # Instance methods (alphabetically sorted) def add_in_place(self, value: T) -> None: ... def add_range_in_place(self, values: Iterable[T]) -> None: ... - def append(self, array2: FSharpArray[T], cons: FSharpCons[T] | None = None) -> FSharpArray[T]: ... # type: ignore[override] + def append(self, array2: FSharpArray[T], cons: FSharpCons[T] | None = None) -> FSharpArray[T]: ... # type: ignore[override] # ty: ignore[invalid-method-override] def average(self, averager: IGenericAverager[T]) -> T: ... def average_by[U](self, projection: Callable[[T], U], averager: IGenericAverager[U]) -> U: ... def choose[U](self, chooser: Callable[[T], Option[U]], cons: FSharpCons[U] | None = None) -> FSharpArray[U]: ... diff --git a/src/fable-library-py/fable_library/int32.py b/src/fable-library-py/fable_library/int32.py index becf748e5b..55e511a8c1 100644 --- a/src/fable-library-py/fable_library/int32.py +++ b/src/fable-library-py/fable_library/int32.py @@ -24,8 +24,8 @@ def div_rem[T: SupportsInt](x: T, y: T, out: FSharpRef[T]) -> T: ... def div_rem[T: SupportsInt](x: T, y: T, out: FSharpRef[T] | None = None) -> T | tuple[T, T]: # Rust wrapper types already use truncated division and remainder - q = x // y # type: ignore[operator] - r = x % y # type: ignore[operator] + q = x // y # type: ignore[operator] # ty: ignore[unsupported-operator] + r = x % y # type: ignore[operator] # ty: ignore[unsupported-operator] if out is None: return (q, r) out.contents = r