This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: nonzero fixer problem
Type: behavior Stage: resolved
Components: 2to3 (2.x to 3.x conversion tool), Documentation Versions: Python 3.11, Python 3.10, Python 3.9
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: benjamin.peterson, docs@python, iritkatriel, josh.r, miss-islington, serhiy.storchaka, shiyuchong
Priority: normal Keywords: patch

Created on 2019-07-16 05:30 by shiyuchong, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 30075 merged iritkatriel, 2021-12-12 17:06
PR 30083 merged miss-islington, 2021-12-13 10:04
PR 30085 merged iritkatriel, 2021-12-13 10:45
Messages (7)
msg348002 - (view) Author: 徐靖 (shiyuchong) Date: 2019-07-16 05:30
An easy problem.
It seems like nonzero fixer can only fix definition, not usage. nonzero fixer cannot fix problems like below:
 a = 1
And there are no cases of __nonzero__() usage in test cases from cases test only definition rename)
It might not be a bug, since in DOC it just says "rename", not "convert". (If it is not a bug, the doc must be considered to be kinds of confusing and should add additional description.)but adding this automatic transformation is really useful in my current work, so at least an optional fixer is needed for 2to3.
A fixer of __oct__(),__hex__() to oct(),hex() is also in need, but 2to3 lacks such fixer.
msg348061 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2019-07-17 14:42
I suspect these fixers were left out simply because no one expected anyone to call the dunder names directly; the whole point of the dunder names is that they're not used directly, being invoked by syntax/context (__nonzero__ being the first thing tried for implicit boolean testing or calls to bool/operator.truth) or by top-level functions (__oct__/__hex__ being called by oct/hex).

The only legitimate use case I can think of off-hand would be in class hierarchies, where a child dunder method is implemented in terms of a super() call to invoke the parent.

Do you have any examples of code bases that rely on this? I've never seen one personally, but I'm not about to claim exhaustive knowledge of all Python code in the world.
msg348093 - (view) Author: 徐靖 (shiyuchong) Date: 2019-07-18 02:13
Got it.
I am just testing all changes in Python 3.X (in preparation for a project porting to 3.7 before I have permission to view the source code), and call __nonzero__() directly for testing. So maybe I cannot provide an example. 
I did not realize that it should not be called directly.
Still, I recommend a documentation change to explain this fact, telling readers the fixer will not change the usage of __nonzero__().
Thanks for your reply.
msg396221 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2021-06-21 10:20
If no one going to provide documentation changes I propose to close this issue.
msg408434 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-13 10:04
New changeset 481f3ffdbe40bd19677a1ba0ac2e7cece8949b47 by Irit Katriel in branch 'main':
bpo-37602: Clarify that the lib2to3 nonzero fixer changes only definitions (GH-30075)
msg408439 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-13 10:45
New changeset 80eb8ab81fbe46497f16071b311c9d8e13ec2d3b by Miss Islington (bot) in branch '3.9':
bpo-37602: Clarify that the lib2to3 nonzero fixer changes only definitions (GH-30075) (GH-30083)
msg408440 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-13 10:47
New changeset 310bae628a9b065d29dbdbf4f7f5beb9fcc72ace by Irit Katriel in branch '3.10':
[3.10] bpo-37602: Clarify that the lib2to3 nonzero fixer changes only definitions (GH-30075) (GH-30085)
Date User Action Args
2022-04-11 14:59:18adminsetgithub: 81783
2021-12-13 10:48:01iritkatrielsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2021-12-13 10:47:42iritkatrielsetmessages: + msg408440
2021-12-13 10:45:59iritkatrielsetmessages: + msg408439
2021-12-13 10:45:18iritkatrielsetpull_requests: + pull_request28306
2021-12-13 10:04:49miss-islingtonsetkeywords: + patch
nosy: + miss-islington

pull_requests: + pull_request28304
stage: patch review
2021-12-13 10:04:39iritkatrielsetmessages: + msg408434
2021-12-12 17:06:10iritkatrielsetstatus: pending -> open
nosy: + iritkatriel

pull_requests: + pull_request28297
2021-06-21 10:20:35serhiy.storchakasetstatus: open -> pending
versions: + Python 3.11, - Python 3.6, Python 3.7, Python 3.8
nosy: + serhiy.storchaka

messages: + msg396221
2020-05-31 13:47:36serhiy.storchakasetversions: + Python 3.6, Python 3.7, Python 3.8, Python 3.9, Python 3.10, - Python 2.7
2019-07-18 02:13:12shiyuchongsetnosy: + docs@python
messages: + msg348093

assignee: docs@python
components: + Documentation
2019-07-17 14:42:32josh.rsetnosy: + josh.r
messages: + msg348061
2019-07-16 07:43:18xtreaksetnosy: + benjamin.peterson
2019-07-16 05:30:27shiyuchongcreate