Skip to content

Conversation

Copy link

Copilot AI commented Sep 30, 2025

This PR implements comprehensive type checking infrastructure using basedpyright for the dify-official-plugins repository, mirroring the type checking setup from the main Dify repository.

Overview

Adds static type checking capabilities to improve code quality and catch type-related bugs during development and CI/CD processes.

Changes Made

Core Infrastructure

  • pyproject.toml - Root configuration with basedpyright development dependency
  • pyrightconfig.json - Type checking configuration optimized for plugin development
  • dev/basedpyright-check - Cross-platform executable script supporting both uv and direct Python execution
  • Makefile - Development targets for type checking, linting, and other common tasks

CI/CD Integration

  • .github/workflows/type-check.yml - Dedicated type checking workflow
  • Updated .github/workflows/pre-check-plugin.yaml - Integrated type checking into existing plugin validation

Documentation

  • DEVELOPMENT.md - Comprehensive development guide covering type checking, setup, and best practices
  • Updated README.md - Added development section with quick start commands
  • Updated .gitignore - Excludes type checking artifacts

Key Features

Flexible Execution

The type checking infrastructure works in multiple environments:

# Using uv (preferred when available)
make type-check

# Direct Python execution (fallback)
./dev/basedpyright-check models/openai

# Path-specific checking
make type-check-path PATH=tools/google_search

Sensible Configuration

The pyrightconfig.json is tuned for plugin development:

  • Disabled missing import errors (plugins have external dependencies)
  • Relaxed unknown type warnings (external library compatibility)
  • Enabled useful checks (unused imports, unnecessary casts, duplicate imports)
  • Basic type checking mode (balanced strictness)

CI Integration

Type checking automatically runs on:

  • Pull requests with Python file changes
  • Plugin-specific validation during pre-check workflow
  • Configurable to run on specific paths or entire repository

Testing

The implementation has been verified with existing plugins:

# Example output showing real type issues found
$ ./dev/basedpyright-check tools/dingo
Found 4 source files
tools/dingo/tools/text_quality_evaluator.py:22:76 - error: Expression of type "None" cannot be assigned to parameter of type "List[str]"
tools/dingo/tools/text_quality_evaluator.py:75:62 - error: Expression of type "None" cannot be assigned to parameter of type "List[str]"
tools/dingo/tools/text_quality_evaluator.py:137:13 - error: Declaration "issues" is obscured by a declaration of the same name
3 errors, 0 warnings, 0 notes

Benefits

  • Early Error Detection: Catch type-related bugs before runtime
  • Improved Code Quality: Encourage proper type annotations and safer code patterns
  • Developer Experience: IDE integration for real-time type checking
  • Consistent Standards: Align with main Dify repository's development practices
  • CI/CD Safety: Prevent type-unsafe code from being merged

Usage for Developers

Quick start:

# Set up development environment
make setup

# Check entire repository
make type-check

# Check specific plugin
make type-check-path PATH=models/gemini

# All development commands
make help

This implementation follows the same patterns and configuration philosophy as the main Dify repository, ensuring consistency across the ecosystem while being tailored for the unique requirements of plugin development.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • astral.sh
    • Triggering command: curl -LsSf REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>add basedpyright to do type check</issue_title>
<issue_description>### Self Checks

  • I have read the Contributing Guide and Language Policy.
  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report, otherwise it will be closed.
  • Please do not modify this template :) and fill in all the required fields.

1. Is this request related to a challenge you're experiencing? Tell me about your story.

same as dify

2. Additional context or comments

No response

3. Can you help us with this feature?

  • I am interested in contributing to this feature.</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #1791

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits September 30, 2025 06:45
Co-authored-by: asukaminato0721 <30024051+asukaminato0721@users.noreply.github.com>
… script

Co-authored-by: asukaminato0721 <30024051+asukaminato0721@users.noreply.github.com>
Copilot AI changed the title [WIP] add basedpyright to do type check Add basedpyright type checking infrastructure to dify-official-plugins Sep 30, 2025
@asukaminato0721
Copy link
Contributor

/gemini review

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.

add basedpyright to do type check

2 participants