Type Stub Generation (IDE Completion)
ErisPulse dynamically discovers modules/adapters via entry-points, and the entry points cannot statically know the specific types of user classes.
The epsdk types command scans installed modules/adapters to generate a type stub file, allowing users to use these types as variable annotations to obtain IDE completion.
Core Design Principles
Stub files export only types and provide no runtime instances:
- All imports are under
TYPE_CHECKING, zero runtime overhead, no behavior changes - Type names use PascalCase form of entry-point names (e.g.,
yunhu→Yunhu), matching the names passed tosdk.adapter.get()/sdk.module.get() - Users use
sdk.module.get(...)/sdk.adapter.get(...)as usual to get instances in their code, only using imported types for variable annotations
Basic Usage
Run the following command in the project root directory:
epsdk types
This will generate _ep_types.py in the current directory, containing types for all installed modules/adapters.
Using in Code
from _ep_types import MyModule, Yunhu
from ErisPulse import sdk
# By using the imported types as variable annotations, IDE will provide completion for the class's methods
my_mod: MyModule = sdk.module.get("MyModule")
my_mod.hello() # ← IDE completes hello
my_adapter: Yunhu = sdk.adapter.get("yunhu")
await my_adapter.Send.To("group", "123").Board(...) # ← Completes platform-specific methods
How It Works
- Scan
erispulse.adapter/erispulse.moduleentry-points - Inspect each adapter/module's actual class information (including module path and qualified name) within the target Python environment via a subprocess
- Generate a
.pyfile, where:- All
from xxx import Yyy as Zzzstatements are included underTYPE_CHECKING Zzzis the PascalCase form of the entry-point name
- All
- The IDE reads the
TYPE_CHECKINGsection to provide code completion; no code is executed at runtime
Example of generated stubs:
# _ep_types.py (auto-generated)
from typing import TYPE_CHECKING
if TYPE_CHECKING:
# Adapters
from MyAdapter.Core import MyAdapter as MyAdapter
from YunhuAdapter.Core import YunhuAdapter as Yunhu
# Modules
from MyModule.Core import Main as MyModule
__all__ = ['MyAdapter', 'Yunhu', 'MyModule']
Command Options
| Option | Description |
|---|---|
-o, --output PATH |
Specify the output file path (default: ./_ep_types.py) |
--force |
Overwrite existing stub files |
--adapters-only |
Scan only adapters |
--modules-only |
Scan only modules |
When to Regenerate
- After installing/uninstalling new modules or adapters
- After modules/adapters update their public APIs
- When IDE auto-completion fails or types are outdated
Relationship with SendDSL Standard Methods
The SendDSL base class already has built-in standard sending methods (Text/Image/Voice/Video/File), and any instance of SendDSL obtained through any method can complete these methods.
The types command is mainly used to complete platform-specific methods (such as Board for Yunhu, Dice for Sandbox) and module-specific methods.
Related Documentation
- SendDSL Detailed Explanation - Standard sending method description
- Getting Started with Adapter Development - Creating an adapter