Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Jul 19, 2025. It is now read-only.

Python: don't crash on complex-number literals#364

Merged

Conversation

jakelishman
Copy link
Contributor

Thisfixes#363: crashing on complex-number literals in Python 2 and 3. I modified the JSON serialiser to string-ify complex numbers, rather than passing them directly as numeric values. That's perhaps not 100% ideal, but it's the same as the behaviour of Ruby'sto_json method. I've added a test that the behaviour works, as well.

Runningcodeclimate analyze on the same test file in issue#363 with the same settings (mass_threshold: 1) now produces the expected output in both Python 2 and Python 3:

Starting analysisRunning duplication: Done!== complex.py (3 issues) ==1-2: Similar blocks of code found in 3 locations. Consider refactoring. [duplication]4-5: Similar blocks of code found in 3 locations. Consider refactoring. [duplication]7-8: Similar blocks of code found in 3 locations. Consider refactoring. [duplication]Analysis complete! Found 3 issues.

hodgestar reacted with heart emoji
@jakelishman
Copy link
ContributorAuthor

Also: if thisis added, it may cause projects to see a spike in detection numbers. Our packageQuTiP would jump from 102 duplication issues to 190, for example.

Copy link

@hodgestarhodgestar left a comment

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

@f-moyaf-moya left a comment

Choose a reason for hiding this comment

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

Nice 👍🏼 , thanks for your contribution.

Complex literals cannot be serialised directly to JSON, but Python's ASTreports them as constant numeric values.  Ruby's `to_json` methodserialies complex numbers to their string representations, so we dosimilar here.  An alternative would be to serialise to a two-elementlist of the real and imaginary parts.
@f-moyaf-moyaforce-pushed thefix-python-complex-numbers branch from5dd5eed to5b01aa3CompareAugust 20, 2021 15:39
@jmcgilljmcgill merged commit3945c66 intocodeclimate:masterAug 20, 2021
@jakelishmanjakelishman deleted the fix-python-complex-numbers branchMarch 4, 2022 22:48
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@hodgestarhodgestarhodgestar approved these changes

@f-moyaf-moyaf-moya approved these changes

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

Complex-number literals raise JSON error in Python
4 participants
@jakelishman@hodgestar@f-moya@jmcgill

[8]ページ先頭

©2009-2025 Movatter.jp