fix(dim): resolve infinite recursion in Dim.__rfloordiv__ by 101-AbdulKhan · Pull Request #6664 · modular/modular · GitHub
Skip to content

fix(dim): resolve infinite recursion in Dim.__rfloordiv__#6664

Open
101-AbdulKhan wants to merge 8 commits into
modular:mainfrom
101-AbdulKhan:101-AbdulKhan
Open

fix(dim): resolve infinite recursion in Dim.__rfloordiv__#6664
101-AbdulKhan wants to merge 8 commits into
modular:mainfrom
101-AbdulKhan:101-AbdulKhan

Conversation

@101-AbdulKhan

@101-AbdulKhan 101-AbdulKhan commented Jun 11, 2026

Copy link
Copy Markdown

When evaluating int // Dim, Python calls Dim.rfloordiv(int). The previous implementation re-evaluated lhs // self, which triggered the same dispatch chain infinitely, causing a RecursionError.

Fix: wrap lhs in Dim() before calling // self, matching the pattern already used by radd and rmul.

Adds two regression tests:

  • test_static_dim_rfloordiv_int: verifies int // StaticDim works correctly
  • test_static_dim_rfloordiv_zero_division_raises: verifies ZeroDivisionError is raised when the denominator Dim is zero

Fixes #6077

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • Performance improvement (includes benchmark results below)
  • Documentation update
  • New feature or public API (requires prior proposal or issue approval)
  • Refactor / internal cleanup (no user-visible change)
  • Build, CI, or tooling change

Motivation

This is a trivial one-line bug fix.
int // StaticDim currently triggers a RecursionError due to recursive redispatch in Dim.__rfloordiv__.

What changed

  • One-line fix in max/python/max/graph/dim.py:
    • changed return lhs // self to return Dim(lhs) // self
  • Added two small regression tests in max/tests/tests/graph/test_dim.py:
    • test_static_dim_rfloordiv_int
    • test_static_dim_rfloordiv_zero_division_raises

Testing

  • Ran:
    • ./bazelw test //max/tests/tests/graph:test_dim
  • New regression tests verify:
    • int // StaticDim works
    • division by zero raises ZeroDivisionError

Linked issue

Fixes #

Type of change

  • Bug fix (non-breaking change that fixes an issue)
  • Performance improvement (includes benchmark results below)
  • Documentation update
  • New feature or public API (requires prior proposal or issue approval)
  • Refactor / internal cleanup (no user-visible change)
  • Build, CI, or tooling change

Motivation

What changed

Testing

Checklist

  • The linked issue above has been reviewed by a maintainer and is
    agreed-upon, or this is a trivial fix that does not need prior
    approval
  • PR is small and focused — I've split larger changes into a sequence of
    smaller PRs where possible (see
    pull request sizes)
  • I ran ./bazelw run format to format my changes
  • I added or updated tests to cover my changes
  • If AI tools assisted with this contribution, I have included an
    Assisted-by: trailer in my commit message or this PR description (see
    AI Tool Use Policy)

When evaluating int // Dim, Python calls Dim.__rfloordiv__(int).
The previous implementation re-evaluated lhs // self, which triggered
the same dispatch chain infinitely causing a RecursionError.

Fix: wrap lhs in Dim() before calling // self, matching the pattern
already used by __radd__ and __rmul__.

Adds two regression tests:
- test_static_dim_rfloordiv_int: verifies int // StaticDim works correctly
- test_static_dim_rfloordiv_zero_division_raises: verifies ZeroDivisionError
  is raised when the denominator Dim is zero

Fixes modular#6595
@101-AbdulKhan 101-AbdulKhan requested a review from a team as a code owner June 11, 2026 06:58
@github-actions

github-actions Bot commented Jun 11, 2026

Copy link
Copy Markdown

@101-AbdulKhan

Copy link
Copy Markdown
Author

modular-cla-bot Bot added a commit to modular/cla that referenced this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: int // StaticDim throws RecursionError: maximum recursion depth exceeded

1 participant