Skip to content

chore(mypy): enable strict type checking for llama_stack_api module#5480

Open
Elbehery wants to merge 2 commits intoogx-ai:mainfrom
Elbehery:20260408_mypy_type_checks_lls_api
Open

chore(mypy): enable strict type checking for llama_stack_api module#5480
Elbehery wants to merge 2 commits intoogx-ai:mainfrom
Elbehery:20260408_mypy_type_checks_lls_api

Conversation

@Elbehery
Copy link
Copy Markdown
Contributor

@Elbehery Elbehery commented Apr 8, 2026

What does this PR do?

Enables strict type checking for llama_stack_api module

  • llama_stack_api: models.py, prompts.py (2 files)
  • core/utils: serialize.py, exec.py (2 files)
  • providers/utils/inference: 6 files (model_registry, embedding_mixin, etc.)
  • log.py (1 file)

Key changes:

  • model_registry.py: Add assertion to narrow provider_resource_id type
  • embedding_mixin.py: Add config attribute type annotation
  • pyproject.toml: Add sentence_transformers to mypy ignore list

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Apr 8, 2026
@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch 5 times, most recently from 4b184ea to fa12f93 Compare April 9, 2026 14:03
Comment thread pyproject.toml Outdated
Comment thread src/llama_stack/providers/utils/inference/model_registry.py Outdated
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 13, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @Elbehery please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Apr 13, 2026
@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch from fa12f93 to ece6543 Compare April 13, 2026 11:23
@mergify mergify Bot removed the needs-rebase label Apr 13, 2026
else:
if llama_model not in ALL_HUGGINGFACE_REPOS_TO_MODEL_DESCRIPTOR:
# Filter out None keys for the error message
valid_models = [k for k in ALL_HUGGINGFACE_REPOS_TO_MODEL_DESCRIPTOR.keys() if k is not None]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

would a more proper solution here be to make sure the list doesn't have None entries? I feel like it shouldn't.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

addressed at b09bd81

Comment thread pyproject.toml
"psycopg2",
"psycopg2.extras",
"psycopg2.extensions",
"sentence_transformers",
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

why was this added?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sentence_transformers was added to the mypy ignore list because:

  1. embedding_mixin.py was removed from the mypy exclude list as part of Phase 1 type checking improvements
  2. That file imports from the sentence_transformers library (line 16: from sentence_transformers import SentenceTransformer)
  3. The sentence_transformers library lacks proper type stubs/annotations

Adding it to [[tool.mypy.overrides]] allows mypy to:

  • ✅ Type-check the rest of embedding_mixin.py
  • ✅ Skip type checking for imports from sentence_transformers (treating them as Any)

This is a standard pattern when enabling strict type checking for code that depends on third-party libraries without type
annotations. The alternative would be keeping embedding_mixin.py in the exclude list, which defeats the purpose of the mypy
improvements.

@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch from ece6543 to b09bd81 Compare April 14, 2026 10:11
@leseb leseb added this pull request to the merge queue Apr 16, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 16, 2026
@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch from b09bd81 to c0890c7 Compare April 16, 2026 13:08
@Elbehery
Copy link
Copy Markdown
Contributor Author

@leseb rebased and updated, please re-approve and re-add 👍🏽

@leseb leseb added this pull request to the merge queue Apr 16, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to a conflict with the base branch Apr 16, 2026
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Apr 16, 2026

This pull request has merge conflicts that must be resolved before it can be merged. @Elbehery please rebase it. https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/working-with-forks/syncing-a-fork

@mergify mergify Bot added the needs-rebase label Apr 16, 2026
@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch from c0890c7 to e5b62e2 Compare April 16, 2026 21:00
@mergify mergify Bot removed the needs-rebase label Apr 16, 2026
  Remove 12 files from mypy exclude list (Phase 1 complete):
  - llama_stack_api: models.py, prompts.py (2 files)
  - core/utils: serialize.py, exec.py (2 files)
  - providers/utils/inference: 6 files (model_registry, embedding_mixin,
  etc.)
  - log.py (1 file)

  Key changes:
  - model_registry.py: Add assertion to narrow provider_resource_id type
  - embedding_mixin.py: Add config attribute type annotation
  - pyproject.toml: Add sentence_transformers to mypy ignore list

Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
…del registry.

This change filters out models without HuggingFace repos at dictionary
creation time rather than at every usage site, ensuring the registry
only contains valid string keys and eliminating the need for None
checks when accessing the dictionary.

Signed-off-by: Mustafa Elbehery <melbeher@redhat.com>
@Elbehery Elbehery force-pushed the 20260408_mypy_type_checks_lls_api branch from e5b62e2 to 2859530 Compare April 17, 2026 09:34
@Elbehery
Copy link
Copy Markdown
Contributor Author

cc @leseb

@Elbehery
Copy link
Copy Markdown
Contributor Author

@leseb could we re-enqueue this ?

cc @mattf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants