Skip to content

gh-102840: Fix confused traceback when floordiv or mod operations happens between Fraction and complex objects#102842

Merged
serhiy-storchaka merged 10 commits into
python:mainfrom
Eclips4:issue-102840
Feb 10, 2024
Merged

gh-102840: Fix confused traceback when floordiv or mod operations happens between Fraction and complex objects#102842
serhiy-storchaka merged 10 commits into
python:mainfrom
Eclips4:issue-102840

Conversation

@Eclips4

@Eclips4 Eclips4 commented Mar 20, 2023

Copy link
Copy Markdown
Member

@Eclips4

Eclips4 commented Mar 20, 2023

Copy link
Copy Markdown
Member Author

cc @skirpichev

Comment thread Lib/fractions.py Outdated
Comment thread Lib/fractions.py Outdated
@Eclips4 Eclips4 requested a review from skirpichev March 20, 2023 12:36
Comment thread Lib/test/test_fractions.py Outdated
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
@Eclips4

Eclips4 commented Mar 20, 2023

Copy link
Copy Markdown
Member Author

Also, I think there no need in NEWS entry. But if someone want it - I'll add it.

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@arhadthedev arhadthedev added the stdlib Standard Library Python modules in the Lib/ directory label Mar 22, 2023
@arhadthedev

Copy link
Copy Markdown
Member

@mdickinson (as a fraction expert)

Comment thread Lib/test/test_fractions.py Outdated

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I do not think that silencing TypeError for any operation is right. It can silence some unexpected errors, it is also not very efficient. It would be better to just not try to perform unsupported operation. I suggest to add an optional parameter in _operator_fallbacks() to specify whether try to handle complex numbers or not. We know which operations are not supported by complex.

Comment thread Lib/test/test_fractions.py Outdated
Comment thread Lib/test/test_fractions.py Outdated
@mdickinson

Copy link
Copy Markdown
Member

I suggest to add an optional parameter in _operator_fallbacks() to specify whether try to handle complex numbers or not.

+1. This sounds like the right approach to me.

@Eclips4

Eclips4 commented Feb 10, 2024

Copy link
Copy Markdown
Member Author

Do we need NEWS entry here? It's improves the user experience, so in my opinion - yes.

@serhiy-storchaka serhiy-storchaka left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is a user visible change, so a NEWS entry will not make bad.

It will help if users wonder about confusing error messages in older Python.

Comment thread Lib/fractions.py Outdated
Comment thread Lib/test/test_fractions.py Outdated

@skirpichev skirpichev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, modulo minor nitpick about default value.

Comment thread Lib/fractions.py Outdated
Comment thread Misc/NEWS.d/next/Library/2024-02-10-15-24-20.gh-issue-102840.4mnDq1.rst Outdated
…mnDq1.rst

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@serhiy-storchaka serhiy-storchaka merged commit 5319c66 into python:main Feb 10, 2024
fsc-eriker pushed a commit to fsc-eriker/cpython that referenced this pull request Feb 14, 2024
scoder added a commit to scoder/quicktions that referenced this pull request Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stdlib Standard Library Python modules in the Lib/ directory

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants