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

Created on 2019-07-16 05:30 by shiyuchong, last changed 2021-06-21 10:20 by serhiy.storchaka.

Messages (4)
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.
Date User Action Args
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