Skip to content

Fix mypy 2.3.0 type errors in the test suite#274

Open
ben-xo wants to merge 1 commit into
graphql-python:mainfrom
mixcloud:fix-mypy-2-3-0-test-type-errors
Open

Fix mypy 2.3.0 type errors in the test suite#274
ben-xo wants to merge 1 commit into
graphql-python:mainfrom
mixcloud:fix-mypy-2-3-0-test-type-errors

Conversation

@ben-xo

@ben-xo ben-xo commented Jul 14, 2026

Copy link
Copy Markdown

mypy 2.3.0 (released 2026-07-13) is stricter and produces 7 errors on unmodified main — CI's mypy<3,>=2.1 floats to it, so the Lint job now fails on every open PR. This fixes them. All changes are test-only with no behavioural change.

Errors fixed

File mypy error Fix
tests/utils/assert_equal_awaitables_or_values.py return value Coroutine vs declared TypeVar T cast("T", …) — the helper returns an awaitable iff its inputs are awaitables
tests/execution/test_abstract.py (×2) conditional is_type_of / type_error sync-vs-async variants must have identical signatures pre-declare each as Callable[..., Any]
tests/execution/test_stream.py (×2) name assigned either a coroutine (throw()) or a str annotate name: Any
tests/execution/test_middleware.py (×2) awaited subscribe(...) item inferred as object, so .data is rejected cast("ExecutionResult", …)

Verification (pinned tool versions)

  • python -m mypy src tests — Success, no issues (mypy 2.3.0)
  • python -m ruff check src tests / ruff format --check src tests — clean (ruff 0.15.21)
  • Affected test files (test_abstract, test_stream, test_middleware) pass unchanged.

mypy 2.3.0 (released 2026-07-13) is stricter and surfaces 7 errors in the test
suite on unmodified main (CI's `mypy<3,>=2.1` floats to it), failing the Lint
job on every open PR. All test-only, no behavioural change.

- tests/utils/assert_equal_awaitables_or_values.py: the awaitable branch
  returns a coroutine where the declared TypeVar `T` is expected; cast it (the
  function returns an awaitable iff its inputs are awaitables).
- tests/execution/test_abstract.py: the conditionally-defined `is_type_of` and
  `type_error` (sync vs async variants) now must have identical signatures;
  pre-declare each with an explicit `Callable[..., Any]`.
- tests/execution/test_stream.py: `name` is assigned either a coroutine
  (`throw()`) or a `str`; annotate it `Any`.
- tests/execution/test_middleware.py: the awaited `subscribe(...)` item is
  inferred as `object`; cast it to `ExecutionResult` before reading `.data`.

mypy src tests, ruff check src tests and ruff format --check src tests are all
clean under the pinned tool versions (mypy 2.3.0, ruff 0.15.21).
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