Skip to content

Make socket operators match Python on integers - #245

Merged
BradyAJohnston merged 2 commits into
mainfrom
fix-operator-semantics
Oct 7, 2026
Merged

BradyAJohnston merged 2 commits into
mainfrom
fix-operator-semantics

Conversation

@BradyAJohnston

Copy link
Copy Markdown
Owner

Adds tests/test_operator_evaluation.py, which evaluates each operator in a tree (via databpy, now a dev dependency) and compares it with Python on the same values. It found:

  • Integer &, |, ^, ~ built Boolean Math, casting to booleans (i | 4 raised). They now build Bit Math.
  • Integer % was truncated modulo (-7 % 3 == -1). Now floored, like Python and float %. Breaking.
  • Integer / truncated (7 / 3 == 2). Now a float Math divide returning a FloatSocket; // stays integer division. Breaking.
  • int_socket < float_socket compared the operands the wrong way round after type promotion.

Codegen lifts follow: Bit Math to &/|/^/~, floored modulo to %, and the guards keep Boolean Math fed by integers (and the reverse) as calls.

@codecov

codecov Bot commented Oct 7, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.87500% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.34%. Comparing base (7a5e9dc) to head (15064c2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
src/nodebpy/export/codegen.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #245      +/-   ##
==========================================
- Coverage   98.34%   98.34%   -0.01%     
==========================================
  Files         101      101              
  Lines       30286    30307      +21     
==========================================
+ Hits        29786    29806      +20     
- Misses        500      501       +1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@BradyAJohnston BradyAJohnston changed the title Make socket operators match Python on integers (520.34.0) Make socket operators match Python on integers Oct 7, 2026
@BradyAJohnston
BradyAJohnston merged commit 7f6fff1 into main Oct 7, 2026
7 checks passed
@BradyAJohnston
BradyAJohnston deleted the fix-operator-semantics branch October 7, 2026 14:08
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