Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow variables to be defined outside a Component #4316

Merged

Conversation

ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Oct 29, 2024

Fixes #4315

Modify prepare_global_scope function in src/backend/base/langflow/utils/validate.py to evaluate classes, functions, and variables defined outside the Component's class.

This makes it easier to implement solutions like #4312

  • Function Changes:

    • Add evaluation of external classes using ast.ClassDef.
    • Add evaluation of external functions using ast.FunctionDef.
    • Add evaluation of external variables using ast.Assign.
  • Unit Tests:

    • Add tests in src/backend/tests/unit/test_validate_code.py to verify the evaluation of external classes, functions, and variables.
    • Include tests for multiple external classes and external variables and functions.

For more details, open the Copilot Workspace session.

Fixes #4315

Modify `prepare_global_scope` function in `src/backend/base/langflow/utils/validate.py` to evaluate classes, functions, and variables defined outside the Component's class.

* **Function Changes:**
  - Add evaluation of external classes using `ast.ClassDef`.
  - Add evaluation of external functions using `ast.FunctionDef`.
  - Add evaluation of external variables using `ast.Assign`.

* **Unit Tests:**
  - Add tests in `src/backend/tests/unit/test_validate_code.py` to verify the evaluation of external classes, functions, and variables.
  - Include tests for multiple external classes and external variables and functions.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/langflow-ai/langflow/issues/4315?shareId=XXXX-XXXX-XXXX-XXXX).
@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Oct 29, 2024
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Oct 29, 2024
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Oct 29, 2024
@ogabrielluiz ogabrielluiz merged commit ccba14b into main Oct 29, 2024
35 of 36 checks passed
@ogabrielluiz ogabrielluiz deleted the ogabrielluiz/fix-evaluate-classes-outside-component branch October 29, 2024 13:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow classes to be defined outside a Component
2 participants