Skip to content

Update type hints and descriptions in clarifai/client folder#781

Merged
zeiler merged 5 commits intomasterfrom
copilot/update-type-hints-descriptions
Sep 16, 2025
Merged

Update type hints and descriptions in clarifai/client folder#781
zeiler merged 5 commits intomasterfrom
copilot/update-type-hints-descriptions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Sep 9, 2025

This PR comprehensively updates type hints and docstring descriptions across all major files in the clarifai/client folder to improve code quality, maintainability, and developer experience.

Changes Made

Type Hint Improvements

  • Replaced generic types with specific ones: Changed str = None to Optional[str] = None for clarity
  • Enhanced dictionary typing: Updated Dict to Dict[str, Any] or more specific types where appropriate
  • Added missing return type annotations: Factory methods now properly return -> 'ClassName'
  • Improved callable typing: gRPC methods now use Callable[..., Any] for better specificity

Documentation Enhancements

  • Expanded parameter descriptions: Added detailed explanations for **kwargs parameters with supported options
  • Enhanced error documentation: Added Raises sections with specific exception types and conditions
  • Improved usage examples: Updated examples to be more realistic and helpful
  • Clarified return value descriptions: Made return types and their purposes more explicit

Files Updated

  • base.py - Core client functionality with improved gRPC method typing
  • search.py - Search API methods with detailed parameter documentation
  • dataset.py - Dataset operations with proper Optional types
  • model.py - Model training and parameter methods with enhanced docs
  • user.py - User API methods with correct type annotations
  • workflow.py - Workflow operations with specific dict typing
  • pipeline.py - Pipeline execution with comprehensive Optional types
  • module.py - Module management with proper type safety
  • pipeline_step.py - Pipeline step operations with consistent typing

Example Improvements

Before:

def get_params(self, template: str = None, save_to: str = 'params.yaml') -> Dict[str, Any]:
    """Returns the model params for the model type and yaml file.
    
    Args:
        template (str): The template to use for the model type.
        yaml_file (str): The yaml file to save the model params.
    """

After:

def get_params(self, template: Optional[str] = None, save_to: str = 'params.yaml') -> Dict[str, Any]:
    """Returns the model params for the model type and saves them to a yaml file.

    Args:
        template (Optional[str]): The template to use for the model type. Required for most
                                model types except 'clusterer' and 'embedding-classifier'.
        save_to (str): The yaml file path to save the model params. Defaults to 'params.yaml'.

    Returns:
        Dict[str, Any]: Dictionary of model params for the model type.

    Raises:
        UserError: If the model type is not trainable, or if template is required but not provided.
    """

Quality Assurance

  • ✅ All files pass linting with ruff
  • ✅ Syntax validation successful for all modified files
  • ✅ No breaking changes to existing API contracts
  • ✅ 100% backward compatibility maintained

This update significantly improves the developer experience by providing better IDE support, more accurate type checking, and clearer documentation while maintaining full backward compatibility.

Fixes #780.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits September 9, 2025 15:44
Co-authored-by: zeiler <2138258+zeiler@users.noreply.github.com>
Co-authored-by: zeiler <2138258+zeiler@users.noreply.github.com>
Copilot AI changed the title [WIP] Update type hints and descriptions Update type hints and descriptions in clarifai/client folder Sep 9, 2025
Copilot AI requested a review from zeiler September 9, 2025 15:48
Copy link
Copy Markdown
Contributor

@luv-bansal luv-bansal left a comment

Choose a reason for hiding this comment

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

@zeiler can you please review this PR if we need this

@zeiler
Copy link
Copy Markdown
Member

zeiler commented Sep 15, 2025

we can add it, doesn't hurt. I was mostly just using this prompt for copilot compared to other coding agents. Flipping through it it does seem relevant and good to merge right?

@zeiler zeiler marked this pull request as ready for review September 15, 2025 15:24
@zeiler zeiler enabled auto-merge (squash) September 15, 2025 16:54
@github-actions
Copy link
Copy Markdown

Code Coverage

Package Line Rate Health
clarifai 43%
clarifai.cli 40%
clarifai.cli.templates 36%
clarifai.client 68%
clarifai.client.auth 67%
clarifai.constants 100%
clarifai.datasets 100%
clarifai.datasets.export 80%
clarifai.datasets.upload 75%
clarifai.datasets.upload.loaders 37%
clarifai.models 100%
clarifai.modules 0%
clarifai.rag 72%
clarifai.runners 52%
clarifai.runners.models 60%
clarifai.runners.pipeline_steps 44%
clarifai.runners.pipelines 80%
clarifai.runners.utils 63%
clarifai.runners.utils.data_types 72%
clarifai.schema 100%
clarifai.urls 60%
clarifai.utils 57%
clarifai.utils.evaluation 67%
clarifai.workflows 95%
Summary 62% (7891 / 12786)

Minimum allowed line rate is 50%

@zeiler zeiler merged commit 8d8048c into master Sep 16, 2025
16 of 17 checks passed
@zeiler zeiler deleted the copilot/update-type-hints-descriptions branch September 16, 2025 08:10
@srikanthbachala20 srikanthbachala20 mentioned this pull request Sep 24, 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.

Update type hints and descriptions

3 participants