Skip to content

Conversation

Copy link

Copilot AI commented Nov 9, 2025

Summary of Changes

Fixes Python 3.8/3.9 compatibility by replacing Python 3.10+ union type syntax (X | Y) with typing.Union[X, Y]. Updated CI to test against Python 3.8, 3.9, 3.10 with proper backport dependencies.

Root cause: Type annotations in _forward.py and _pruning.py used PEP 604 union syntax (np.ndarray | None), which is only available in Python 3.10+.

Changes:

  • pymars/_compat.py: Added importlib.metadata compatibility shim for future use
  • pymars/_forward.py, pymars/_pruning.py: Replaced 7 instances of X | Y with Union[X, Y]
  • .github/workflows/ci.yml: Pinned actions to v4, reduced matrix to [3.8, 3.9, 3.10], added importlib-metadata for Python < 3.10

No dict union operators or importlib.metadata runtime imports were found during audit.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing

  • Ran existing tests to ensure no regressions
  • Manual testing performed

All 107 tests pass locally on Python 3.12. CI validation pending for Python 3.8, 3.9, 3.10.

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Related Issues

Related to #114

Additional Context

Minimal, surgical changes—only type annotations and CI configuration modified. No public API changes.

Original prompt

Create a branch fix/py38-39-ci-tests, apply minimal compatibility fixes so tests and CI succeed on Python 3.8 and 3.9, and open a PR.

Changes to make:

  1. Add mars/_compat.py with exact contents:

try:
import importlib.metadata as importlib_metadata # type: ignore
except Exception:
import importlib_metadata # type: ignore

all = ("importlib_metadata",)

  1. Find and replace runtime imports of importlib.metadata to use the shim. For each file that contains import importlib.metadata or from importlib.metadata import X, update to either:
  • from mars._compat import importlib_metadata
  • and then reference importlib_metadata.X accordingly (or assign X = importlib_metadata.X when code previously used from importlib.metadata import X).

Make only runtime-code edits; do not change tests unless failing tests prove necessary.

  1. Detect and replace dict union operator usages (a | b) used for dict merging with {**a, **b} or a.copy(); a.update(b) as appropriate. Use AST scanning to ensure BitOr replacement is only for dict merge usages, not integer bit flags.

  2. Add/Update .github/workflows/ci.yml to pin actions to stable majors and include python-version matrix [3.8,3.9,3.10]. Ensure importlib-metadata backport is installed for python<3.8. Use actions/checkout@v4 and actions/setup-python@v4. The job should run pytest.

  3. Commit changes to a new branch fix/py38-39-ci-tests and open a PR titled "Fix tests and CI for Python 3.8/3.9 compatibility" with a description that:

  1. Run CI for the PR and iterate on any failures. If tests require skipping on older Pythons, add pytest.mark.skipif with a clear reason.

Notes:

  • Keep changes minimal and avoid public API changes.
  • If any ambiguities arise, add TODO comments and document them in the PR description.

Please create the branch, apply the changes, run tests in CI, and open the PR. If any step fails, include logs in the PR and report back here with the PR URL and CI status.

This pull request was created as a result of the following prompt from Copilot chat.

Create a branch fix/py38-39-ci-tests, apply minimal compatibility fixes so tests and CI succeed on Python 3.8 and 3.9, and open a PR.

Changes to make:

  1. Add mars/_compat.py with exact contents:

try:
import importlib.metadata as importlib_metadata # type: ignore
except Exception:
import importlib_metadata # type: ignore

all = ("importlib_metadata",)

  1. Find and replace runtime imports of importlib.metadata to use the shim. For each file that contains import importlib.metadata or from importlib.metadata import X, update to either:
  • from mars._compat import importlib_metadata
  • and then reference importlib_metadata.X accordingly (or assign X = importlib_metadata.X when code previously used from importlib.metadata import X).

Make only runtime-code edits; do not change tests unless failing tests prove necessary.

  1. Detect and replace dict union operator usages (a | b) used for dict merging with {**a, **b} or a.copy(); a.update(b) as appropriate. Use AST scanning to ensure BitOr replacement is only for dict merge usages, not integer bit flags.

  2. Add/Update .github/workflows/ci.yml to pin actions to stable majors and include python-version matrix [3.8,3.9,3.10]. Ensure importlib-metadata backport is installed for python<3.8. Use actions/checkout@v4 and actions/setup-python@v4. The job should run pytest.

  3. Commit changes to a new branch fix/py38-39-ci-tests and open a PR titled "Fix tests and CI for Python 3.8/3.9 compatibility" with a description that:

  1. Run CI for the PR and iterate on any failures. If tests require skipping on older Pythons, add pytest.mark.skipif with a clear reason.

Notes:

  • Keep changes minimal and avoid public API changes.
  • If any ambiguities arise, add TODO comments and document them in the PR description.

Please create the branch, apply the changes, run tests in CI, and open the PR. If any step fails, include logs in the PR and report back here with the PR URL and CI status.


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

@coderabbitai
Copy link

coderabbitai bot commented Nov 9, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

- Add pymars/_compat.py with importlib.metadata shim
- Replace Union type annotations (X | Y) with Union[X, Y] in _forward.py and _pruning.py
- Update CI workflow to use actions v4 and include importlib-metadata for Python < 3.10
- Test matrix now focuses on Python 3.8, 3.9, 3.10

Co-authored-by: edithatogo <15080672+edithatogo@users.noreply.github.com>
Copilot AI changed the title [WIP] Add compatibility fixes for Python 3.8 and 3.9 in CI Fix Python 3.8/3.9 compatibility: Union type syntax and CI configuration Nov 9, 2025
Copilot AI requested a review from edithatogo November 9, 2025 07:01
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.

2 participants