
This issue trackerhas been migrated toGitHub, and is currentlyread-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.
Created on2020-01-09 12:43 byfrancois-durand, last changed2022-04-11 14:59 byadmin. This issue is nowclosed.
| Pull Requests | |||
|---|---|---|---|
| URL | Status | Linked | Edit |
| PR 18017 | merged | seberg,2020-01-15 22:47 | |
| PR 18376 | merged | miss-islington,2020-02-06 14:55 | |
| PR 18377 | merged | miss-islington,2020-02-06 14:57 | |
| Messages (12) | |||
|---|---|---|---|
| msg359673 -(view) | Author: François Durand (francois-durand) | Date: 2020-01-09 12:43 | |
As of now, fractions.Fraction.__bool__ is implemented as: ``return a._numerator != 0``. However, this does not necessary return a bool (which would be desired). In particular, when the numerator is a numpy integer, this returns a numpy bool instead. Another solution would be to implement fractions.Fraction.__bool__ as: ``return bool(numerator)``. What do you think?This message follows a thread here:https://github.com/numpy/numpy/issues/15277 . | |||
| msg359675 -(view) | Author: Mark Dickinson (mark.dickinson)*![]() | Date: 2020-01-09 13:14 | |
Agreed that __bool__ should return an actual bool.``return bool(a._numerator)`` does seem like the obvious way to do this. | |||
| msg359677 -(view) | Author: Mark Dickinson (mark.dickinson)*![]() | Date: 2020-01-09 13:25 | |
For completeness and to save people going to the NumPy tracker, here's an example of the problem:Python 3.8.1 (default, Jan 5 2020, 21:32:35) [Clang 10.0.1 (clang-1001.0.46.4)] on darwinType "help", "copyright", "credits" or "license" for more information.>>> import fractions, numpy>>> f = fractions.Fraction(numpy.int64(1), 2)>>> not fTraceback (most recent call last): File "<stdin>", line 1, in <module>TypeError: __bool__ should return bool, returned numpy.bool_ | |||
| msg359679 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2020-01-09 13:36 | |
> ``return bool(a._numerator)`` does seem like the obvious way to do this.Yes, it's a good fix. It's used on other places.--numbers.Complex.__bool__() also uses "self != 0". Is it an issue? | |||
| msg359681 -(view) | Author: Sebastian Berg (seberg)* | Date: 2020-01-09 14:02 | |
Thanks for the quick responses.@Victor Stinner, I suppose you could change `numbers.Complex.__bool__()` by adding the no-op bool to make it: `bool(self != 0)`.But I am not sure I feel it is necessary. NumPy is a bit a strange in that it uses its own boolean scalar, and it is easy to override the slot for such objects. | |||
| msg360077 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2020-01-15 21:40 | |
Does someone want to propose a PR to modify fractions.Fraction.__bool__() to use "return bool(a._numerator)"? | |||
| msg361237 -(view) | Author: Ido Michael (Ido Michael)* | Date: 2020-02-02 14:31 | |
Hi all,I think this issue can be closed right?Saw a successful PR. | |||
| msg361238 -(view) | Author: SilentGhost (SilentGhost)*![]() | Date: 2020-02-02 14:37 | |
"Successful" PR would be merged into master. This issue is still in "patch review" stage. | |||
| msg361488 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2020-02-06 14:54 | |
New changeset427c84f13f7719e6014a21bd1b81efdc02a046fb by Sebastian Berg in branch 'master':bpo-39274: Ensure Fraction.__bool__() returns a bool (GH-18017)https://github.com/python/cpython/commit/427c84f13f7719e6014a21bd1b81efdc02a046fb | |||
| msg361489 -(view) | Author: STINNER Victor (vstinner)*![]() | Date: 2020-02-06 14:59 | |
Thanks Sebastian Berg for the fix, and thanks François Durand for the bug report! This issue is fixed in the master branch, and backports to 3.7 and 3.8 will land soon automatically (once the CI tests pass). | |||
| msg361491 -(view) | Author: miss-islington (miss-islington) | Date: 2020-02-06 15:13 | |
New changeset0d03a1028200646479ef9bb0ad8973d0e73f9525 by Miss Islington (bot) in branch '3.8':bpo-39274: Ensure Fraction.__bool__() returns a bool (GH-18017)https://github.com/python/cpython/commit/0d03a1028200646479ef9bb0ad8973d0e73f9525 | |||
| msg361492 -(view) | Author: miss-islington (miss-islington) | Date: 2020-02-06 15:14 | |
New changeset705d271d553b77fd170d27ab8d0f11f638c7f145 by Miss Islington (bot) in branch '3.7':bpo-39274: Ensure Fraction.__bool__() returns a bool (GH-18017)https://github.com/python/cpython/commit/705d271d553b77fd170d27ab8d0f11f638c7f145 | |||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:25 | admin | set | github: 83455 |
| 2020-02-06 15:14:42 | miss-islington | set | messages: +msg361492 |
| 2020-02-06 15:13:43 | miss-islington | set | nosy: +miss-islington messages: +msg361491 |
| 2020-02-06 14:59:07 | vstinner | set | status: open -> closed resolution: fixed messages: +msg361489 stage: patch review -> resolved |
| 2020-02-06 14:57:06 | miss-islington | set | pull_requests: +pull_request17754 |
| 2020-02-06 14:55:51 | miss-islington | set | pull_requests: +pull_request17753 |
| 2020-02-06 14:54:11 | vstinner | set | messages: +msg361488 |
| 2020-02-02 14:37:51 | SilentGhost | set | nosy: +SilentGhost messages: +msg361238 |
| 2020-02-02 14:31:35 | Ido Michael | set | nosy: +Ido Michael messages: +msg361237 |
| 2020-01-15 22:47:23 | seberg | set | keywords: +patch stage: patch review pull_requests: +pull_request17412 |
| 2020-01-15 21:40:05 | vstinner | set | keywords: +newcomer friendly messages: +msg360077 versions: - Python 3.5, Python 3.6, Python 3.7, Python 3.8 |
| 2020-01-11 01:11:53 | terry.reedy | set | messages: -msg359674 |
| 2020-01-09 14:02:46 | seberg | set | nosy: +seberg messages: +msg359681 |
| 2020-01-09 13:36:51 | vstinner | set | nosy: +vstinner messages: +msg359679 |
| 2020-01-09 13:25:31 | mark.dickinson | set | messages: +msg359677 |
| 2020-01-09 13:14:20 | mark.dickinson | set | messages: +msg359675 |
| 2020-01-09 13:02:19 | xtreak | set | nosy: +rhettinger,mark.dickinson |
| 2020-01-09 12:45:17 | francois-durand | set | messages: +msg359674 |
| 2020-01-09 12:43:51 | francois-durand | create | |