Issue27855
Created on 2016-08-25 00:11 by rippey.e, last changed 2022-04-11 14:58 by admin. This issue is now closed.
| Messages (8) | |||
|---|---|---|---|
| msg273613 - (view) | Author: E Rippey (rippey.e) | Date: 2016-08-25 00:11 | |
The "has_key" fixer in 2to3 produces wrong code on the following example: input:"a.has_key(b)and x" output:"b in aand x" Note the lack of space before "and" in the input. |
|||
| msg273622 - (view) | Author: Eric N. Vander Weele (ericvw) * | Date: 2016-08-25 04:21 | |
I am unable to replicate this issue with '2to3' from Python 2.7.12, Python 3.4.5, nor Python 3.5.2. Below is what I get with the versions I mentioned above. --- $ cat test.py a.has_key(b) and x $ 2to3 test.py RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored test.py --- test.py (original) +++ test.py (refactored) @@ -1 +1 @@ -a.has_key(b) and x +b in a and x RefactoringTool: Files that need to be modified: RefactoringTool: test.py --- |
|||
| msg273623 - (view) | Author: Josh Rosenberg (josh.r) * ![]() |
Date: 2016-08-25 04:55 | |
Eric, remove the space from after the has_key call to match OP: $ cat test.py a.has_key(b)and x It's legal to omit the space there. |
|||
| msg273624 - (view) | Author: Josh Rosenberg (josh.r) * ![]() |
Date: 2016-08-25 04:59 | |
Testing it myself that way: C:\>type test.py a.has_key(b)and x C:\>"C:\Program Files\Python 3.5\Tools\scripts\2to3.py" test.py RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored test.py --- test.py (original) +++ test.py (refactored) @@ -1 +1 @@ -a.has_key(b)and x +b in aand x RefactoringTool: Files that need to be modified: RefactoringTool: test.py |
|||
| msg273626 - (view) | Author: Eric N. Vander Weele (ericvw) * | Date: 2016-08-25 05:26 | |
> Eric, remove the space from after the has_key call to match OP: > $ cat test.py > a.has_key(b)and x Good catch. Disregard msg273622 from me - I am able to replicate what the OP has described. |
|||
| msg273646 - (view) | Author: R. David Murray (r.david.murray) * ![]() |
Date: 2016-08-25 12:20 | |
I don't think it is necessary or reasonable to expect 2to3 to handle this. It is a tool for the developer to use, so just clean up the input. |
|||
| msg273673 - (view) | Author: E Rippey (rippey.e) | Date: 2016-08-25 18:45 | |
I have one line change to "Lib/lib2to3/fixes/fix_has_key.py" that will resolve this issue. Would a patch be accepted? It doesn't seem like the input is unusually contorted. |
|||
| msg273715 - (view) | Author: Terry J. Reedy (terry.reedy) * ![]() |
Date: 2016-08-26 18:49 | |
If you don't want to sign the CA, https://www.python.org/psf/contrib/, and upload a file without a guarantee, which is never given ;-), just give the patch in a text message. While it may be unreasonable to *expect* 2to3 to handle this, it also might not be unreasonable for it to do so. It would be especially useful if one were converting to Py3 and not planning to maintain the 2.x code. My concern is that this might be one of multiple similar situations, so that patching just one might not be all that helpful. But I have not looked at the list of fixers to determine is other are affected. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:58:35 | admin | set | github: 72042 |
| 2021-10-20 22:47:17 | iritkatriel | set | status: open -> closed superseder: Close 2to3 issues and list them here |
| 2016-08-26 18:49:15 | terry.reedy | set | nosy:
+ terry.reedy, benjamin.peterson messages:
+ msg273715 |
| 2016-08-25 18:45:35 | rippey.e | set | status: closed -> open messages: + msg273673 |
| 2016-08-25 12:20:37 | r.david.murray | set | title: 2to3: Wrong code output w/ has_key -> 2to3: Wrong code output w/ has_key without trailing space |
| 2016-08-25 12:20:11 | r.david.murray | set | status: open -> closed nosy:
+ r.david.murray resolution: rejected |
| 2016-08-25 05:26:05 | ericvw | set | messages: + msg273626 |
| 2016-08-25 04:59:15 | josh.r | set | messages: + msg273624 |
| 2016-08-25 04:55:45 | josh.r | set | nosy:
+ josh.r messages: + msg273623 |
| 2016-08-25 04:21:41 | ericvw | set | nosy:
+ ericvw messages: + msg273622 |
| 2016-08-25 00:11:33 | rippey.e | create | |

