Skip to content

Conversation

tharun634
Copy link

@tharun634 tharun634 commented Oct 4, 2025

resolves #1091

cc: @badmonster0

All the mypy errors for reference:

Run .venv/bin/python -m mypy python examples

examples/text_embedding_qdrant/main.py:3: error: Cannot find implementation or library stub for module named "qdrant_client"  [import-not-found]
examples/text_embedding/main.py:2: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/text_embedding/main.py:3: error: Cannot find implementation or library stub for module named "pgvector.psycopg"  [import-not-found]
examples/postgres_source/main.py:6: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/postgres_source/main.py:7: error: Cannot find implementation or library stub for module named "pgvector.psycopg"  [import-not-found]
examples/postgres_source/main.py:7: note: Error code "import-not-found" not covered by "type: ignore" comment
examples/postgres_source/main.py:8: error: Cannot find implementation or library stub for module named "psycopg.rows"  [import-not-found]
examples/postgres_source/main.py:137: error: Returning Any from function declared to return "list[dict[str, Any]]"  [no-any-return]
examples/pdf_embedding/main.py:6: error: Cannot find implementation or library stub for module named "marker.config.parser"  [import-not-found]
examples/pdf_embedding/main.py:7: error: Cannot find implementation or library stub for module named "marker.converters.pdf"  [import-not-found]
examples/pdf_embedding/main.py:8: error: Cannot find implementation or library stub for module named "marker.models"  [import-not-found]
examples/pdf_embedding/main.py:9: error: Cannot find implementation or library stub for module named "marker.output"  [import-not-found]
examples/pdf_embedding/main.py:10: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/pdf_embedding/main.py:25: error: Function is missing a return type annotation  [no-untyped-def]
examples/pdf_embedding/main.py:25: note: Use "-> None" if function does not return a value
examples/pdf_embedding/main.py:36: error: Returning Any from function declared to return "str"  [no-any-return]
examples/pdf_embedding/main.py:55: error: Function is missing a return type annotation  [no-untyped-def]
examples/pdf_embedding/main.py:99: error: Function is missing a return type annotation  [no-untyped-def]
examples/pdf_embedding/main.py:133: error: Function is missing a return type annotation  [no-untyped-def]
examples/pdf_embedding/main.py:133: note: Use "-> None" if function does not return a value
examples/pdf_embedding/main.py:149: error: Call to untyped function "_main" in typed context  [no-untyped-call]
examples/patient_intake_extraction/main.py:6: error: Cannot find implementation or library stub for module named "markitdown"  [import-not-found]
examples/patient_intake_extraction/main.py:7: error: Cannot find implementation or library stub for module named "openai"  [import-not-found]
examples/patient_intake_extraction/main.py:100: error: Function is missing a return type annotation  [no-untyped-def]
examples/patient_intake_extraction/main.py:100: note: Use "-> None" if function does not return a value
examples/patient_intake_extraction/main.py:110: error: Returning Any from function declared to return "str"  [no-any-return]
examples/patient_intake_extraction/main.py:114: error: Function is missing a return type annotation  [no-untyped-def]
examples/paper_metadata/main.py:7: error: Cannot find implementation or library stub for module named "marker.config.parser"  [import-not-found]
examples/paper_metadata/main.py:8: error: Cannot find implementation or library stub for module named "marker.converters.pdf"  [import-not-found]
examples/paper_metadata/main.py:9: error: Cannot find implementation or library stub for module named "marker.models"  [import-not-found]
examples/paper_metadata/main.py:10: error: Cannot find implementation or library stub for module named "marker.output"  [import-not-found]
examples/paper_metadata/main.py:12: error: Cannot find implementation or library stub for module named "pypdf"  [import-not-found]
examples/paper_metadata/main.py:70: error: Returning Any from function declared to return "str"  [no-any-return]
examples/paper_metadata/main.py:130: error: Module has no attribute "CustomLanguageSpec"  [attr-defined]
examples/multi_format_indexing/main.py:7: error: Cannot find implementation or library stub for module named "pdf2image"  [import-not-found]
examples/multi_format_indexing/main.py:10: error: Cannot find implementation or library stub for module named "qdrant_client"  [import-not-found]
examples/manuals_llm_extraction/main.py:4: error: Cannot find implementation or library stub for module named "marker.converters.pdf"  [import-not-found]
examples/manuals_llm_extraction/main.py:5: error: Cannot find implementation or library stub for module named "marker.models"  [import-not-found]
examples/manuals_llm_extraction/main.py:6: error: Cannot find implementation or library stub for module named "marker.output"  [import-not-found]
examples/manuals_llm_extraction/main.py:7: error: Cannot find implementation or library stub for module named "marker.config.parser"  [import-not-found]
examples/manuals_llm_extraction/main.py:23: error: Function is missing a return type annotation  [no-untyped-def]
examples/manuals_llm_extraction/main.py:23: note: Use "-> None" if function does not return a value
examples/manuals_llm_extraction/main.py:34: error: Returning Any from function declared to return "str"  [no-any-return]
examples/manuals_llm_extraction/main.py:91: error: Function is missing a return type annotation  [no-untyped-def]
examples/image_search/main.py:11: error: Cannot find implementation or library stub for module named "fastapi"  [import-not-found]
examples/image_search/main.py:12: error: Cannot find implementation or library stub for module named "fastapi.middleware.cors"  [import-not-found]
examples/image_search/main.py:13: error: Cannot find implementation or library stub for module named "fastapi.staticfiles"  [import-not-found]
examples/image_search/main.py:15: error: Cannot find implementation or library stub for module named "qdrant_client"  [import-not-found]
examples/image_search/main.py:40: error: Returning Any from function declared to return "list[float]"  [no-any-return]
examples/image_search/main.py:46: error: Parameter 1 of Literal[...] is invalid  [valid-type]
examples/image_search/main.py:55: error: Returning Any from function declared to return "Vector[float, Any]"  [no-any-return]
examples/image_search/main.py:114: error: Argument 1 to "asynccontextmanager" has incompatible type "Callable[[Any], None]"; expected "Callable[[Any], AsyncIterator[Never]]"  [arg-type]
examples/image_search/main.py:115: error: The return type of an async generator function should be "AsyncGenerator" or one of its supertypes  [misc]
examples/image_search/main.py:144: error: Untyped decorator makes function "search" untyped  [misc]
examples/image_search/colpali_main.py:8: error: Cannot find implementation or library stub for module named "fastapi"  [import-not-found]
examples/image_search/colpali_main.py:9: error: Cannot find implementation or library stub for module named "fastapi.middleware.cors"  [import-not-found]
examples/image_search/colpali_main.py:10: error: Cannot find implementation or library stub for module named "fastapi.staticfiles"  [import-not-found]
examples/image_search/colpali_main.py:11: error: Cannot find implementation or library stub for module named "qdrant_client"  [import-not-found]
examples/image_search/colpali_main.py:73: error: Argument 1 to "asynccontextmanager" has incompatible type "Callable[[Any], None]"; expected "Callable[[Any], AsyncIterator[Never]]"  [arg-type]
examples/image_search/colpali_main.py:74: error: The return type of an async generator function should be "AsyncGenerator" or one of its supertypes  [misc]
examples/image_search/colpali_main.py:103: error: Untyped decorator makes function "search" untyped  [misc]
examples/gdrive_text_embedding/main.py:2: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/gdrive_text_embedding/main.py:24: error: Function is missing a return type annotation  [no-untyped-def]
examples/gdrive_text_embedding/main.py:74: error: Function is missing a return type annotation  [no-untyped-def]
examples/gdrive_text_embedding/main.py:97: error: Function is missing a return type annotation  [no-untyped-def]
examples/gdrive_text_embedding/main.py:97: note: Use "-> None" if function does not return a value
examples/gdrive_text_embedding/main.py:118: error: Call to untyped function "_main" in typed context  [no-untyped-call]
examples/fastapi_server_docker/main.py:2: error: Cannot find implementation or library stub for module named "uvicorn"  [import-not-found]
examples/fastapi_server_docker/main.py:4: error: Cannot find implementation or library stub for module named "fastapi"  [import-not-found]
examples/fastapi_server_docker/main.py:6: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/fastapi_server_docker/main.py:27: error: Function is missing a return type annotation  [no-untyped-def]
examples/fastapi_server_docker/main.py:68: error: Function is missing a return type annotation  [no-untyped-def]
examples/fastapi_server_docker/main.py:92: error: Function is missing a return type annotation  [no-untyped-def]
examples/fastapi_server_docker/main.py:106: error: Untyped decorator makes function "search_endpoint" untyped  [misc]
examples/fastapi_server_docker/main.py:107: error: Function is missing a return type annotation  [no-untyped-def]
examples/face_recognition/main.py:56: error: Module has no attribute "face_locations"  [attr-defined]
examples/face_recognition/main.py:84: error: Module has no attribute "face_encodings"  [attr-defined]
examples/face_recognition/main.py:88: error: Returning Any from function declared to return "Vector[float, None]"  [no-any-return]
examples/custom_output_files/main.py:99: error: Returning Any from function declared to return "str"  [no-any-return]
examples/code_embedding/main.py:2: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/code_embedding/main.py:3: error: Cannot find implementation or library stub for module named "pgvector.psycopg"  [import-not-found]
examples/azure_blob_embedding/main.py:2: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/amazon_s3_embedding/main.py:2: error: Cannot find implementation or library stub for module named "psycopg_pool"  [import-not-found]
examples/amazon_s3_embedding/main.py:2: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
Found 77 errors in 17 files (checked 75 source files)

pyo3 didn't like my machine's python installation so did all my testing on Github Action runner 😄

Copy link
Member

Choose a reason for hiding this comment

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

Why do we rename these files? Please revert these changes.

It's unnecessary and will break existing links to these directoreis.

Copy link
Author

Choose a reason for hiding this comment

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

There is also a Python PIP dependency called face_recognition, let me try reverting and testing

Copy link
Member

Choose a reason for hiding this comment

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

They're top-level directories for applications. We don't need __init__.py for them.

Copy link
Author

Choose a reason for hiding this comment

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

examples\azure_blob_embedding\main.py: error: Duplicate module named "main" (also at "examples\amazon_s3_embedding\main.py")
examples\azure_blob_embedding\main.py: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mapping-file-paths-to-modules for more info
examples\azure_blob_embedding\main.py: note: Common resolutions include: a) using `--exclude` to avoid checking one of them, b) adding `__init__.py` somewhere, c) using `--explicit-package-bases` or adjusting MYPYPATH

You get this error otherwise.

So we will have to run the examples mypy check separately on the CI since --explicit-package-bases is a global flag and not a module level flag. therefore cannot be set in pyproject.toml

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I think running each example as a separate project is exactly what we want.

It's also aligned with how users use cocoindex (they have their own separate project). The goal of these are setting examples for users so they can start to use cocoindex easily.

pyproject.toml Outdated
Comment on lines 94 to 105
"qdrant_client",
"psycopg_pool",
"pgvector.psycopg",
"psycopg.rows",
"marker.*",
"pypdf",
"pdf2image",
"markitdown",
"openai",
"fastapi.*",
"uvicorn",
"face_recognition",
Copy link
Member

Choose a reason for hiding this comment

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

Please don't add them here.

They're only used by examples, not the cocoindex library. Examples depends on the library, not the other way, so we shouldn't introduce dependency for the library because of we use them in examples.

Copy link
Author

Choose a reason for hiding this comment

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

It's not a python PIP dependency addition, I am just excluding these modules from producing an mypy missing imports error.

You can refer to the description of the PR for the [import-not-found] errors

# --- Response Models ---


class SearchResult(BaseModel):
Copy link
Member

Choose a reason for hiding this comment

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

Consider use a dataclass here instead, which is available in Python standard library. In this way we keep these examples simple. We want to keep them as simple as possible; users don't need to install and understand another library unless it's really needed for the example.

@tharun634 tharun634 reopened this Oct 5, 2025
@tharun634 tharun634 requested a review from georgeh0 October 5, 2025 13:23
@@ -1,5 +1,5 @@
from dotenv import load_dotenv
from psycopg_pool import ConnectionPool
from psycopg_pool import ConnectionPool # type: ignore[import-not-found]
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need to add this?

It's already included in amazon_s3_embedding/pyproject.toml. As long as we run pip install . under the specific example directory, we shouldn't get "import not found", right?

Copy link
Author

Choose a reason for hiding this comment

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

Right, I was under the impression that we would be running mypy with the venv of the main project. Will install dependencies per example and retest

@tharun634 tharun634 closed this Oct 6, 2025
@tharun634 tharun634 reopened this Oct 6, 2025
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.

Check out for mypy type errors in the examples and clean up
2 participants