Skip to content

maintenance: relax & organize dependencies, simplify function signatures#19

Merged
anmorgunov merged 16 commits intomainfrom
dev/relax-deps
Jul 28, 2025
Merged

maintenance: relax & organize dependencies, simplify function signatures#19
anmorgunov merged 16 commits intomainfrom
dev/relax-deps

Conversation

@anmorgunov
Copy link
Contributor

@anmorgunov anmorgunov commented Jul 28, 2025

Summary by CodeRabbit

  • New Features

    • Added a dedicated workflow for running automated tests on pull requests.
  • Refactor

    • Updated training analysis to remove pandas dependency, improving performance and flexibility for plotting and data handling.
    • Streamlined model loading and beam search creation for more efficient configuration handling.
  • Style

    • Improved code consistency by enforcing strict iterable length checks in various zip operations.
    • Simplified file opening and assignment expressions for improved readability.
  • Chores

    • Updated dependency management: switched to minimum version requirements, restructured optional dependencies, and enhanced build system configuration.
    • Revised linting and pre-commit configurations, removing unused tools and refining type checks.

Comment on lines 6 to 42
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python 3.13
uses: actions/setup-python@v4
with:
python-version: '3.13'

- name: Install uv
run: |
curl -LsSf https://astral.sh/uv/install.sh | sh
echo "$HOME/.cargo/bin" >> $GITHUB_PATH

- name: Cache dependencies
uses: actions/cache@v4
with:
path: |
~/.cache/uv
~/.uv
.venv
key: ${{ runner.os }}-uv-${{ hashFiles('pyproject.toml') }}
restore-keys: |
${{ runner.os }}-uv-

- name: Create and activate virtual environment
run: |
uv venv
echo "$PWD/.venv/bin" >> $GITHUB_PATH

- name: Install dependencies
run: uv pip install -e ".[dev]"

- name: Run tests
run: pytest -v No newline at end of file

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}

Copilot Autofix

AI 7 months ago

To fix the issue, we will add a permissions block at the root of the workflow file. This block will specify the minimal permissions required for the workflow to function. Based on the provided steps, the workflow primarily interacts with the repository to read contents (e.g., pyproject.toml for caching). Therefore, we will set contents: read as the permission. If additional permissions are required in the future, they can be added explicitly.


Suggested changeset 1
.github/workflows/testing.yml

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml
--- a/.github/workflows/testing.yml
+++ b/.github/workflows/testing.yml
@@ -3,2 +3,4 @@
 on: [pull_request]
+permissions:
+  contents: read
 jobs:
EOF
@@ -3,2 +3,4 @@
on: [pull_request]
permissions:
contents: read
jobs:
Copilot is powered by AI and may make mistakes. Always verify output.
@anmorgunov
Copy link
Contributor Author

@coderabbitai let's do a review

@coderabbitai
Copy link

coderabbitai bot commented Jul 28, 2025

Tip

For best results, initiate chat on the files or code changes.

@anmorgunov I'll review the changes in this maintenance PR, focusing on the dependency updates and function signature simplifications.

[review]

@coderabbitai
Copy link

coderabbitai bot commented Jul 28, 2025

Walkthrough

This update refactors code quality and CI workflows, revises dependency management, and improves type and file handling across the codebase. Major changes include splitting linting and testing workflows, removing pandas in favor of native structures, enforcing stricter iterable checks, updating dependency specifications, and enhancing model and beam search interfaces.

Changes

Cohort / File(s) Change Summary
GitHub Actions Workflows
.github/workflows/linting.yml, .github/workflows/testing.yml
Linting and testing workflows are separated; linting focuses on ruff and mypy, while testing installs dependencies and runs pytest in a new workflow.
Pre-commit and Linting Config
.pre-commit-config.yaml, pyproject.toml
isort hook removed; mypy config updated to exclude tests; dependency pins relaxed to minimum versions; dev and vis dependency groups restructured; ruff lint rules expanded.
File and Iterable Handling Improvements
data/process.py, scripts/solve_compounds.py, src/directmultistep/utils/io.py
File reading/writing now uses context managers; unnecessary open() mode arguments removed; zip calls made strict; minor whitespace and type hinting updates.
Analysis and Plotting Refactor
src/directmultistep/analysis/training.py
Replaces pandas DataFrames with lists of dicts for data loading and plotting; adds log scale options; updates all related functions and main execution.
Strict Iterable Checks
src/directmultistep/analysis/paper/linear_vs_convergent.py, src/directmultistep/utils/post_process.py, use-examples/paper-figures.py
All zip calls now use strict=True to enforce equal-length iterables; minor variable and formatting tweaks.
Model and Generation Interface Updates
src/directmultistep/generate.py, src/directmultistep/generation/tensor_gen.py
Model loading function renamed and extended with device forcing; beam search creation now uses a processing object; BeamSearchOptimized.decode gains progress bar and token processor options.
Minor Logic and Syntax Adjustments
src/directmultistep/generation/eval.py, src/directmultistep/generation/generation.py, src/directmultistep/model/components/moe.py, src/directmultistep/model/config.py, src/directmultistep/model/factory.py, src/directmultistep/training/lightning.py, use-examples/eval-subset.py
Syntax simplifications, improved type hints, updated exception chaining, and streamlined conditional logic.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant GitHub Actions
    participant Linter (ruff/mypy)
    participant Tester (pytest)

    User->>GitHub Actions: Push or PR event
    GitHub Actions->>Linter (ruff/mypy): Run linting workflow
    Linter (ruff/mypy)-->>GitHub Actions: Report lint/type status
    GitHub Actions->>Tester (pytest): Run testing workflow (on PR)
    Tester (pytest)-->>GitHub Actions: Report test results
Loading
sequenceDiagram
    participant User
    participant ModelLoader
    participant BeamSearchFactory
    participant RoutesProcessing

    User->>ModelLoader: load_published_model(name, ckpt_dir, device)
    ModelLoader-->>User: model
    User->>RoutesProcessing: instantiate(config)
    User->>BeamSearchFactory: create_beam_search(model, beam_size, rds)
    BeamSearchFactory-->>User: BeamSearch object
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~40 minutes

Poem

A warren of code, now neat and spry,
With stricter zips and workflows that fly.
Pandas have wandered, lists now reside,
Linting and testing march side by side.
Dependencies pruned, configs refined—
This bunny’s proud of the code you’ve aligned!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev/relax-deps

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

♻️ Duplicate comments (1)
.github/workflows/testing.yml (1)

3-6: Add explicit permissions to limit GITHUB_TOKEN scope

The workflow should explicitly define permissions for security best practices.

 on: [pull_request]
+
+permissions:
+  contents: read
+
 jobs:
🧹 Nitpick comments (9)
use-examples/eval-subset.py (1)

10-10: Consider simplifying redundant conditional logic.

Since __mode__ is constrained to only "local" or "cluster" by the assertion on line 8, the condition __mode__ == "local" or __mode__ in ["cluster"] will always be true and could be removed entirely.

-if __mode__ == "local" or __mode__ in ["cluster"]:
-    base_path = Path(__file__).resolve().parent.parent
+base_path = Path(__file__).resolve().parent.parent
.github/workflows/linting.yml (1)

49-49: Add missing newline at end of file.

The file should end with a newline character following Unix text file conventions.

-      run: mypy .
+      run: mypy .
+
src/directmultistep/generation/eval.py (1)

179-184: Shadowing pathlib.Path with loop variable path may confuse readers

Inside the beam-search loop, the variable name path shadows the imported Path class from pathlib, which is frequently referenced elsewhere in the codebase. Renaming this loop variable (e.g. to path_start_BL) will improve readability and avoid accidental misuse.

.pre-commit-config.yaml (1)

23-25: Minor YAML hygiene – add newline at EOF & quote regex

YAML-lint flags a missing trailing newline. While touching the file, quoting the regex avoids future parsing surprises.

 types: [python]
-exclude: ^(tests/)
-args: ["--config-file=pyproject.toml"]
+# path regexp is interpreted by pre-commit, keep it explicit
+exclude: "^(tests/)"
+args: ["--config-file=pyproject.toml"]
+
src/directmultistep/generation/generation.py (1)

194-195: Walrus operator here hurts clarity more than it helps

The one-off assignment within append() saves one line but obscures intent. A simple two-step approach is easier to read and debug.

-                beam_idxs_BS1_nt[B_idx][S_idx].append(chosen_idx := top_k_BS_nt[B_idx][S_idx])
-                beam_log_probs_BS_nt[B_idx][S_idx] += np.log(normalized_probs_BLS[B_idx, -1, chosen_idx].item())
+                chosen_idx = top_k_BS_nt[B_idx][S_idx]
+                beam_idxs_BS1_nt[B_idx][S_idx].append(chosen_idx)
+                beam_log_probs_BS_nt[B_idx][S_idx] += np.log(
+                    normalized_probs_BLS[B_idx, -1, chosen_idx].item()
+                )
.github/workflows/testing.yml (1)

42-42: Fix formatting issues

Remove trailing spaces and add a newline at the end of the file.

-      run: pytest -v 
+      run: pytest -v
src/directmultistep/analysis/training.py (3)

12-26: Fix docstring typo and improve error handling documentation

The docstring has a typo and could be more descriptive about the silent failure behavior.

-def _cast_numeric_values(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
-    """attempts to cognize string values into floats. fails silently."""
+def _cast_numeric_values(data: list[dict[str, Any]]) -> list[dict[str, Any]]:
+    """Convert string values to floats where possible, setting None on failure."""

91-98: Improve function docstring

The docstring should be more professional.

-    """makes a graph. you get it."""
+    """Plot training curves for multiple runs with configurable axes scaling."""

135-136: Improve function docstring

The docstring should be more descriptive.

-    """makes another graph. also obvious."""
+    """Plot learning rate curves for multiple training runs."""
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bb44519 and a3045db.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (20)
  • .github/workflows/linting.yml (2 hunks)
  • .github/workflows/testing.yml (1 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • data/process.py (5 hunks)
  • pyproject.toml (3 hunks)
  • scripts/solve_compounds.py (1 hunks)
  • src/directmultistep/analysis/paper/linear_vs_convergent.py (5 hunks)
  • src/directmultistep/analysis/training.py (4 hunks)
  • src/directmultistep/generate.py (5 hunks)
  • src/directmultistep/generation/eval.py (2 hunks)
  • src/directmultistep/generation/generation.py (1 hunks)
  • src/directmultistep/generation/tensor_gen.py (4 hunks)
  • src/directmultistep/model/components/moe.py (2 hunks)
  • src/directmultistep/model/config.py (2 hunks)
  • src/directmultistep/model/factory.py (2 hunks)
  • src/directmultistep/training/lightning.py (1 hunks)
  • src/directmultistep/utils/io.py (4 hunks)
  • src/directmultistep/utils/post_process.py (4 hunks)
  • use-examples/eval-subset.py (1 hunks)
  • use-examples/paper-figures.py (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (5)
src/directmultistep/model/config.py (1)
src/directmultistep/generation/eval.py (1)
  • load (102-115)
data/process.py (1)
src/directmultistep/utils/io.py (1)
  • save_dataset_sm (75-84)
src/directmultistep/model/factory.py (1)
src/directmultistep/model/config.py (4)
  • EncoderAConfig (90-99)
  • MoEEncoderConfig (103-114)
  • TransformerConfig (11-71)
  • MoEDecoderConfig (75-86)
src/directmultistep/generation/tensor_gen.py (1)
src/directmultistep/generation/generation.py (1)
  • decode (148-235)
src/directmultistep/analysis/training.py (1)
src/directmultistep/analysis/style.py (1)
  • apply_development_style (161-170)
🪛 actionlint (1.7.7)
.github/workflows/testing.yml

13-13: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🪛 GitHub Check: CodeQL
.github/workflows/testing.yml

[warning] 6-42: Workflow does not contain permissions
Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {{contents: read}}

🪛 YAMLlint (1.37.1)
.github/workflows/testing.yml

[error] 42-42: no new line character at the end of file

(new-line-at-end-of-file)


[error] 42-42: trailing spaces

(trailing-spaces)

.github/workflows/linting.yml

[error] 49-49: no new line character at the end of file

(new-line-at-end-of-file)

.pre-commit-config.yaml

[error] 25-25: no new line character at the end of file

(new-line-at-end-of-file)

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: lint
🔇 Additional comments (34)
src/directmultistep/training/lightning.py (2)

1-1: LGTM: Import modernization

Good update to use collections.abc.Callable instead of typing.Callable, which is the recommended approach for Python 3.9+ and aligns with PEP 585.


190-197: LGTM: Simplified scheduler configuration

The removal of the verbose=False parameter simplifies the LambdaLR instantiation. This is likely due to either the parameter being deprecated or becoming the default behavior in newer PyTorch versions.

use-examples/paper-figures.py (1)

158-158: LGTM: Added strict length checking

Good addition of strict=True to the zip function. This ensures that configs and datasets have matching lengths and will raise a ValueError if they don't, preventing potential silent bugs from mismatched iterables.

src/directmultistep/utils/io.py (4)

96-98: LGTM: Added strict length checking to zip operations

Excellent addition of strict=True to both zip calls. This ensures that the dictionary keys and values have matching lengths, preventing silent bugs from mismatched data structures.


110-110: LGTM: Simplified dictionary iteration

Good simplification by removing the unnecessary .keys() call. Iterating directly over the dictionary is equivalent and more concise.


126-126: LGTM: Removed redundant file mode specification

The explicit "r" mode is redundant since it's the default for open(). This change simplifies the code while maintaining the same functionality.


175-175: LGTM: Removed redundant file mode specification

Same improvement as above - removing the explicit "r" mode since it's the default behavior.

scripts/solve_compounds.py (1)

45-45: LGTM: Consistent removal of redundant file mode specifications

All four changes consistently remove the explicit "r" mode from open() calls, aligning with the broader codebase cleanup. Since "r" is the default mode, these changes simplify the code while maintaining identical functionality.

Also applies to: 48-48, 56-56, 60-60

src/directmultistep/model/config.py (2)

3-3: LGTM: Modernized typing imports

Good update to remove the unused Type import from the typing module, keeping only the necessary Literal and TypeVar imports. This aligns with the type annotation modernization in the codebase.


60-60: LGTM: Updated type annotation to use built-in type

Excellent modernization of the type annotation from Type[T] to type[T], following PEP 585 recommendations for Python 3.9+. This change is consistent with the broader effort to modernize type annotations across the codebase.

src/directmultistep/model/components/moe.py (2)

194-194: Good modernization of super() call.

The simplified super() syntax is the preferred approach in Python 3, improving readability while maintaining the same functionality.


225-225: Clean simplification of conditional logic.

The ternary operator effectively condenses the capacity limiting logic while maintaining clarity and the same behavior.

src/directmultistep/utils/post_process.py (4)

1-1: Good modernization of type imports.

Moving from typing.Iterator to collections.abc.Iterator follows PEP 585 recommendations and is the preferred approach for Python 3.9+.


106-108: Excellent addition of strict zip validation.

Adding strict=True ensures that paths_NS2n and correct_paths have matching lengths, preventing silent data truncation and potential bugs from misaligned data.


153-153: Minor formatting improvement.

Adding proper spacing around the multiplication operator improves code readability and follows PEP 8 style guidelines.


475-475: Consistent application of strict zip validation.

Adding strict=True ensures match_accuracy and n_steps_list have matching lengths, maintaining data integrity in the step-length correlation analysis.

src/directmultistep/analysis/paper/linear_vs_convergent.py (5)

333-333: Consistent strict zip validation for plotting data.

Adding strict=True ensures proper alignment between categories and positions in the plotting logic, preventing potential visualization errors.


341-341: Proper validation of results and trace names alignment.

The strict zip ensures each result set has a corresponding trace name, preventing data misalignment in the comparative plots.


411-411: Important three-way data alignment validation.

The strict zip on result_paths, datasets, and configs ensures all three data sources are properly aligned, which is critical for accurate analysis results.


472-472: Consistent three-way validation in subplot function.

Maintains the same strict alignment validation as the main plotting function, ensuring consistency across different visualization approaches.


485-485: Good use of underscore prefix for unused variable.

Prefixing _route_type with an underscore clearly indicates the variable is intentionally unused, following Python naming conventions.

.github/workflows/linting.yml (3)

1-1: Good workflow name clarification.

Renaming to "Linting" better reflects the focused purpose of this workflow, especially with testing moved to a separate workflow file.


6-6: Consistent job naming.

The lint job name aligns well with the workflow's focused purpose and improves clarity.


40-40: Good modernization of dependency installation.

Using uv sync is the preferred approach for dependency synchronization with uv, providing better handling of lock files and dependency resolution.

src/directmultistep/generation/eval.py (1)

68-70: Prefer explicit exception over assert for runtime-critical validation

assert statements are stripped when Python is run with the -O flag, which would silently bypass the dataset-name validation in production. Replace with an explicit check and raised exception to guarantee enforcement.

-assert self.eval_dataset in allowed_ds, (
-    f"Eval dataset {self.eval_dataset} not in allowed datasets: {allowed_ds}"
-)
+if self.eval_dataset not in allowed_ds:
+    raise ValueError(
+        f"Eval dataset {self.eval_dataset} is not among the allowed datasets {allowed_ds}"
+    )

[ suggest_essential_refactor ]

data/process.py (1)

98-100: 👍 Context manager adopted for pickle dump

Good catch converting the raw open() call into a with block – aligns with the new lint rule and ensures file handles are closed.

src/directmultistep/generation/tensor_gen.py (2)

54-61: Well-designed backward-compatible API enhancement

The addition of progress_bar and token_processor parameters maintains backward compatibility while adding useful functionality. The optional token processor pattern is a clean way to allow custom token processing.


96-97: Clean conditional progress bar implementation

Good use of conditional expression to handle the progress bar display based on the parameter.

src/directmultistep/generate.py (2)

35-37: Good addition of device control parameter

The force_device parameter provides flexibility for explicit device selection while maintaining backward compatibility with the default behavior.


59-73: Improved modularity in beam search creation

Excellent refactoring to accept RoutesProcessing object directly instead of re-reading the config file. This reduces I/O operations and centralizes configuration handling.

pyproject.toml (3)

5-12: Good dependency management improvements

Switching from exact pins to minimum version requirements provides more flexibility while maintaining compatibility. The removal of pandas aligns with the codebase refactoring.


25-27: Proper build system configuration

Good addition of build system requirements for package distribution.


75-83: Comprehensive linting configuration

The explicit rule selection provides clear visibility into which linting rules are enforced. Ignoring E501 is appropriate given the 120-character line length setting.

src/directmultistep/analysis/training.py (1)

28-50: Good refactoring to remove pandas dependency

The implementation using csv.DictReader and native Python structures is clean and efficient. The type casting approach handles missing data appropriately.

Comment on lines +13 to +16
uses: actions/setup-python@v4
with:
python-version: '3.13'

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Update actions/setup-python to v5

The action version is outdated and may not run properly on newer GitHub Actions runners.

-    - name: Set up Python 3.13
-      uses: actions/setup-python@v4
-      with:
-        python-version: '3.13'
+    - name: Set up Python 3.13
+      uses: actions/setup-python@v5
+      with:
+        python-version: '3.13'
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
uses: actions/setup-python@v4
with:
python-version: '3.13'
- name: Set up Python 3.13
uses: actions/setup-python@v5
with:
python-version: '3.13'
🧰 Tools
🪛 actionlint (1.7.7)

13-13: the runner of "actions/setup-python@v4" action is too old to run on GitHub Actions. update the action's version to fix this issue

(action)

🤖 Prompt for AI Agents
In .github/workflows/testing.yml around lines 13 to 16, the setup-python action
is using version v4, which is outdated. Update the version from
actions/setup-python@v4 to actions/setup-python@v5 to ensure compatibility with
newer GitHub Actions runners and improve reliability.

Comment on lines +91 to 95
if not isinstance(self.config.encoder, EncoderAConfig | MoEEncoderConfig):
raise TypeError("Encoder config must be either EncoderAConfig or MoEEncoderConfig")
if not isinstance(self.config.decoder, (TransformerConfig, MoEDecoderConfig)):
if not isinstance(self.config.decoder, TransformerConfig | MoEDecoderConfig):
raise TypeError("Decoder config must be either TransformerConfig or MoEDecoderConfig")

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

isinstance(obj, A | B) is invalid – will raise TypeError at runtime

Using the PEP-604 union operator inside isinstance is not supported. Pass a tuple of classes instead.

-        if not isinstance(self.config.encoder, EncoderAConfig | MoEEncoderConfig):
+        if not isinstance(self.config.encoder, (EncoderAConfig, MoEEncoderConfig)):
             raise TypeError("Encoder config must be either EncoderAConfig or MoEEncoderConfig")
-        if not isinstance(self.config.decoder, TransformerConfig | MoEDecoderConfig):
+        if not isinstance(self.config.decoder, (TransformerConfig, MoEDecoderConfig)):
             raise TypeError("Decoder config must be either TransformerConfig or MoEDecoderConfig")
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if not isinstance(self.config.encoder, EncoderAConfig | MoEEncoderConfig):
raise TypeError("Encoder config must be either EncoderAConfig or MoEEncoderConfig")
if not isinstance(self.config.decoder, (TransformerConfig, MoEDecoderConfig)):
if not isinstance(self.config.decoder, TransformerConfig | MoEDecoderConfig):
raise TypeError("Decoder config must be either TransformerConfig or MoEDecoderConfig")
if not isinstance(self.config.encoder, (EncoderAConfig, MoEEncoderConfig)):
raise TypeError("Encoder config must be either EncoderAConfig or MoEEncoderConfig")
if not isinstance(self.config.decoder, (TransformerConfig, MoEDecoderConfig)):
raise TypeError("Decoder config must be either TransformerConfig or MoEDecoderConfig")
🤖 Prompt for AI Agents
In src/directmultistep/model/factory.py around lines 91 to 95, the use of the
PEP-604 union operator (A | B) inside isinstance calls is invalid and causes a
TypeError at runtime. Replace the union operator with a tuple of classes in the
isinstance checks, for example, use isinstance(self.config.encoder,
(EncoderAConfig, MoEEncoderConfig)) and similarly for the decoder check.

@anmorgunov anmorgunov merged commit 238057b into main Jul 28, 2025
8 checks passed
@anmorgunov anmorgunov deleted the dev/relax-deps branch July 28, 2025 11:22
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.

1 participant