Improve Type Hints for BaseNode and Its Subclasses #11076

Closed
opened 2026-02-21 18:54:38 -05:00 by yindo · 0 comments
Owner

Originally created by @QuantumGhost on GitHub (Mar 14, 2025).

Originally assigned to: @QuantumGhost on GitHub.

Self Checks

  • I have searched for existing issues search for existing issues, including closed ones.
  • I confirm that I am using English to submit this report (我已阅读并同意 Language Policy).
  • [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:)
  • 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.

The core.workflow.nodes.base.node.BaseNode class is a generic class with a type parameter GenericNodeData. This type parameter is intended to describe the type of the _node_data_cls field, which stores the class type of the corresponding data for each subclass of BaseNode. However, the current type annotation for _node_data_cls is type[BaseNodeData], which does not accurately reflect the fact that each subclass of BaseNode has its own specific type for _node_data_cls.

2. Additional context or comments

Proposed Solution

To better represent the relationship between BaseNode subclasses and their corresponding _node_data_cls types, we should change the type annotation of _node_data_cls to type[GenericNodeData]. This change will more accurately indicate that each subclass has its own unique _node_data_cls type.

Additionally, we should remove the type casting of node_data to BaseNodeData in the BaseNode.__init__ method, as well as remove the redundant type annotations for _node_data_cls in the subclasses.

3. Can you help us with this feature?

  • I am interested in contributing to this feature.
Originally created by @QuantumGhost on GitHub (Mar 14, 2025). Originally assigned to: @QuantumGhost on GitHub. ### Self Checks - [x] I have searched for existing issues [search for existing issues](https://github.com/langgenius/dify/issues), including closed ones. - [x] I confirm that I am using English to submit this report (我已阅读并同意 [Language Policy](https://github.com/langgenius/dify/issues/1542)). - [x] [FOR CHINESE USERS] 请务必使用英文提交 Issue,否则会被关闭。谢谢!:) - [x] 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. The `core.workflow.nodes.base.node.BaseNode` class is a generic class with a type parameter `GenericNodeData`. This type parameter is intended to describe the type of the `_node_data_cls` field, which stores the class type of the corresponding data for each subclass of `BaseNode`. However, the current type annotation for `_node_data_cls` is `type[BaseNodeData]`, which does not accurately reflect the fact that each subclass of `BaseNode` has its own specific type for `_node_data_cls`. ### 2. Additional context or comments ## Proposed Solution To better represent the relationship between `BaseNode` subclasses and their corresponding `_node_data_cls` types, we should change the type annotation of `_node_data_cls` to `type[GenericNodeData]`. This change will more accurately indicate that each subclass has its own unique `_node_data_cls` type. Additionally, we should remove the type casting of `node_data` to `BaseNodeData` in the `BaseNode.__init__` method, as well as remove the redundant type annotations for `_node_data_cls` in the subclasses. ### 3. Can you help us with this feature? - [x] I am interested in contributing to this feature.
yindo closed this issue 2026-02-21 18:54:38 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#11076