Skip to content

chore: add mypy support #1257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 15, 2025
Merged

chore: add mypy support #1257

merged 7 commits into from
Jul 15, 2025

Conversation

hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jul 15, 2025

Important

Adds mypy type checking with strict settings, integrates it into CI, and fixes type-related issues across the codebase.

  • Behavior:
    • Adds mypy type checking to the codebase with strict settings in pyproject.toml.
    • Integrates mypy into the CI pipeline in ci.yml and pre-commit hooks in .pre-commit-config.yaml.
    • Fixes type-related issues in langfuse/_client/attributes.py, langfuse/_client/client.py, and langfuse/_client/observe.py.
  • Type Annotations:
    • Adds type hints to all functions across the codebase, including langfuse/_client/datasets.py, langfuse/_client/get_client.py, and langfuse/_client/resource_manager.py.
    • Ensures OpenTelemetry tracing is type-safe with proper Tracer typing.
    • Improves type safety in chat message compilation and async/sync wrappers.
  • Misc:
    • Adds py.typed marker file for PEP 561 compliance.
    • Updates pyproject.toml to include mypy as a dependency and configure its settings.

This description was created by Ellipsis for 6728515. You can customize this summary. It will automatically update as commits are pushed.


Disclaimer: Experimental PR review

Greptile Summary

This PR adds comprehensive mypy type checking support to the langfuse-python codebase. The changes span across multiple files and include:

  1. Adding proper type hints and return type annotations to all functions
  2. Adding a py.typed marker file to indicate PEP 561 type checking support
  3. Configuring mypy with strict settings in pyproject.toml
  4. Adding mypy to the CI pipeline and pre-commit hooks
  5. Fixing several type-related issues discovered during the process

Key changes include:

  • Making OpenTelemetry tracing type-safe with proper Tracer typing
  • Improving type safety in chat message compilation
  • Adding proper type hints for async/sync wrappers
  • Fixing defaultdict usage in OpenAI integration
  • Adding comprehensive type checking in the CI pipeline

Confidence score: 5/5

  1. This PR is extremely safe to merge as it only adds type hints without modifying runtime behavior
  2. The changes are well-tested through CI and pre-commit hooks, covering all critical code paths
  3. While all files have been modified, particular attention should be paid to:
    • langfuse/openai.py (complex integration point)
    • langfuse/_client/observe.py (async/sync handling)
    • langfuse/model.py (message compilation changes)

27 files reviewed, 2 comments
Edit PR Review Bot Settings | Greptile

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

Reviewing changes made in this pull request

@hassiebp hassiebp merged commit 31e4b73 into main Jul 15, 2025
11 checks passed
@hassiebp hassiebp deleted the add-mypy branch July 15, 2025 12:58
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.

bug: Mypy doesn't consider typing from Langfuse, because of missing py.typed
1 participant