Skip to content

Conversation

@hassiebp
Copy link
Contributor

@hassiebp hassiebp commented Jun 5, 2025

Important

Add type annotations to functions across multiple files and integrate mypy for type checking.

  • Type Annotations:
    • Add return type annotations to functions in client.py, datasets.py, utils.py, environment.py, error_logging.py, prompt_cache.py, serializer.py, CallbackHandler.py, utils.py, media.py, model.py, and openai.py.
    • Annotate function parameters with specific types, such as Any, Optional, Dict, List, Callable, Union, Literal, and Tuple.
  • Mypy Integration:
    • Add mypy as a development dependency in pyproject.toml.
    • Configure mypy settings in pyproject.toml to enforce strict type checking, including disallow_untyped_defs, warn_return_any, and strict_equality.
    • Add mypy overrides for specific modules to ignore missing imports.

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

Greptile Summary

Disclaimer: Experimental PR review

Adds comprehensive MyPy static type checking support across the langfuse-python codebase, improving type safety and code maintainability without modifying runtime behavior.

  • Added explicit return type annotations and parameter type hints to all core modules (client.py, utils.py, serializer.py)
  • Configured strict MyPy settings in pyproject.toml with third-party import overrides
  • Fixed potential type-related issues like replacing mutable default arguments in error_logging.py
  • Improved type hints in integration modules (langchain, openai) with proper generics and Optional types
  • Added comprehensive type annotations in media handling and dataset modules

@hassiebp hassiebp marked this pull request as draft June 5, 2025 14:16
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.

14 file(s) reviewed, 3 comment(s)
Edit PR Review Bot Settings | Greptile


def _wrap_task(self, key: str, task):
def wrapped():
def _wrap_task(self, key: str, task: Any) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The return type Any is too permissive and doesn't match the actual Callable[[], None] return type of this function


@functools.wraps(func)
def wrapper(*args, **kwargs):
def wrapper(*args: Any, **kwargs: Any) -> Any:
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Missing return value in wrapper function when exception occurs. Should return None explicitly.

Comment on lines +92 to +116
[[tool.mypy.overrides]]
module = [
"langchain.*",
"openai.*",
"chromadb.*",
"tiktoken.*",
"google.*",
"anthropic.*",
"cohere.*",
"dashscope.*",
"pymongo.*",
"bson.*",
"boto3.*",
"llama_index.*",
"respx.*",
"bs4.*",
"lark.*",
"huggingface_hub.*",
"backoff.*",
"wrapt.*",
"packaging.*",
"requests.*",
"opentelemetry.*"
]
ignore_missing_imports = true
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: The mypy overrides list is comprehensive but missing type ignores for newer dependencies like langgraph. Add langgraph to the overrides list.

Suggested change
[[tool.mypy.overrides]]
module = [
"langchain.*",
"openai.*",
"chromadb.*",
"tiktoken.*",
"google.*",
"anthropic.*",
"cohere.*",
"dashscope.*",
"pymongo.*",
"bson.*",
"boto3.*",
"llama_index.*",
"respx.*",
"bs4.*",
"lark.*",
"huggingface_hub.*",
"backoff.*",
"wrapt.*",
"packaging.*",
"requests.*",
"opentelemetry.*"
]
ignore_missing_imports = true
[[tool.mypy.overrides]]
module = [
"langchain.*",
"openai.*",
"chromadb.*",
"tiktoken.*",
"google.*",
"anthropic.*",
"cohere.*",
"dashscope.*",
"pymongo.*",
"bson.*",
"boto3.*",
"llama_index.*",
"respx.*",
"bs4.*",
"lark.*",
"huggingface_hub.*",
"backoff.*",
"wrapt.*",
"packaging.*",
"requests.*",
"opentelemetry.*",
"langgraph.*"
]
ignore_missing_imports = true

@hassiebp hassiebp closed this Jul 14, 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.

2 participants