Content-Length: 319142 | pFad | http://github.com/micropython/micropython/pull/17383

73 Fix parsing complex numbers like -1+1j by jepler · Pull Request #17383 · micropython/micropython · GitHub
Skip to content

Fix parsing complex numbers like -1+1j #17383

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

Closed
wants to merge 2 commits into from

Conversation

jepler
Copy link
Contributor

@jepler jepler commented May 28, 2025

Summary

Over in adafruit#10297 a contributor noticed a bug and offered a fix for parsing of complex numbers like complex("-1+1j"). The fix looked minimal and based on testing seems correct, so I decided to offer it over here.

Testing

I added a pair of initially failing tests to the test suite, and then checked that the fix made them pass.

Trade-offs and Alternatives

I also noticed that the non-standard complex literal complex("1 1j") is accepted by micropython but not python3. It is accepted as an argument to the built in complex function but not as a literal in source code. A more complete fix might make this into an error too.

Signed-off-by: Jeff Epler <jepler@gmail.com>
Copy link

codecov bot commented May 28, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.54%. Comparing base (2dada06) to head (8b1232d).
Report is 65 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #17383   +/-   ##
=======================================
  Coverage   98.54%   98.54%           
=======================================
  Files         169      169           
  Lines       21898    21898           
=======================================
  Hits        21579    21579           
  Misses        319      319           

☔ View full report in Codecov by Sentry.
📢 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@jepler jepler force-pushed the complex-sign-error branch from 2388d64 to 93245bf Compare May 28, 2025 18:56
Copy link

Code size report:

   bare-arm:    +0 +0.000% 
minimal x86:    +0 +0.000% 
   unix x64:   -64 -0.007% standard
      stm32:    -4 -0.001% PYBV10
     mimxrt:    +8 +0.002% TEENSY40
        rp2:    +8 +0.001% RPI_PICO_W
       samd:    +0 +0.000% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:    +6 +0.001% VIRT_RV32

@dpgeorge dpgeorge added the py-core Relates to py/ directory in source label May 29, 2025
If a complex literal had a negative real part and a positive
complex part, it was not parsed properly.

Co-Authored-By: ComplexSymbol
 <141301057+ComplexSymbol@users.noreply.github.com>
Signed-off-by: Jeff Epler <jepler@gmail.com>
@jepler jepler force-pushed the complex-sign-error branch from 93245bf to 8b1232d Compare May 29, 2025 06:47
Copy link
Member

@dpgeorge dpgeorge left a comment

Choose a reason for hiding this comment

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

I like this fix. It's definitely needed to fix the bug, and is very minimal.

@dpgeorge
Copy link
Member

Rebased, squashed and merged in 2ce63b1

Thanks for the neat fix!

@dpgeorge dpgeorge closed this Jun 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
py-core Relates to py/ directory in source
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/micropython/micropython/pull/17383

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy