Skip to content

Improve type detection for BaseNode Inputs and Outputs #263

@coderabbitai

Description

@coderabbitai

Problem

Currently, the BaseNode framework requires all Inputs and Outputs fields to be typed as str, which leads to several issues:

  1. Type casting required: Developers need to manually cast values (e.g., int(self.inputs.items))
  2. Type ignore comments: Multiple # type: ignore comments are needed to suppress type checker warnings
  3. Loss of type safety: The framework doesn't leverage Python's type system effectively
  4. Poor developer experience: IDE support and autocompletion are limited

Example

Currently we need to write:

class Inputs(BaseModel):
    items: str  # Should be int

async def execute(self):
    count = int(self.inputs.items)  # type: ignore
    return [self.Outputs(processed=str(i)) for i in range(count)]

Instead of the more natural:

class Inputs(BaseModel):
    items: int

async def execute(self):
    count = self.inputs.items
    return [self.Outputs(processed=str(i)) for i in range(count)]

Expected Outcome

The BaseNode framework should:

  • Support proper type annotations for Inputs and Outputs fields
  • Automatically handle type conversion/validation where needed
  • Eliminate the need for manual type casting and type ignore comments
  • Provide better IDE support and type safety

Context

This issue was identified during code review of comprehensive test cases for BaseNode.

Related PR: #262
Related Comment: #262 (comment)

cc: @NiveditJain

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions