Skip to content

Fix Concordia Island embedder return type so examples typecheck - #400

Open
anugrah55 wants to merge 1 commit into
google-deepmind:mainfrom
anugrah55:fix-concordia-island-embedder-type
Open

anugrah55 wants to merge 1 commit into
google-deepmind:mainfrom
anugrah55:fix-concordia-island-embedder-type

Conversation

@anugrah55

Copy link
Copy Markdown
Contributor

The Test examples workflow has failed on every push to main since the Concordia Island example was added on 2026-10-06, and it fails on every open PR for the same reason. The failing step is "Typecheck examples":

ERROR Returned type `Tensor` is not assignable to declared return type `ndarray` [bad-return]
   --> examples/concordia_island/run.py:647:14
646 |     def embedder(text: str) -> np.ndarray:
647 |       return embedder_model.encode(text)

Cause

SentenceTransformer.encode is overloaded. Called with no conversion arguments, pyrefly resolves it to the first overload, which returns Tensor. At runtime the default is convert_to_numpy=True, so the function does return an np.ndarray; only the static type is wrong.

Fix

Pass convert_to_numpy=True explicitly. That matches the runtime default, so behaviour does not change, and it selects the overload that returns np.ndarray.

Validation

Python 3.14 with the versions pinned in requirements.txt (pyrefly 1.2.0, sentence-transformers 5.6.1, torch 2.14.0, numpy 2.4.6):

  • pyrefly check examples/concordia_island/run.py: 1 error on main, 0 with this change.
  • pyrefly check examples/**/*.py: the bad-return error above is gone. I could not get a fully clean local run of the whole glob because my environment did not have every example dependency installed, so the CI run on this PR is the real check.
  • pylint --errors-only examples/concordia_island/run.py: clean.

`SentenceTransformer.encode` is overloaded, and with no conversion arguments
pyrefly resolves the call to the overload that returns `Tensor`. The
`embedder` wrapper is annotated as returning `np.ndarray`, so
`pyrefly check examples/**/*.py` fails with `bad-return`.

Pass `convert_to_numpy=True` explicitly. That is already the runtime default,
so behaviour is unchanged, and it selects the overload that returns
`np.ndarray`.

This branch has not been deployed

No deployments
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