Title: Fixers find, rfind, etc in 'string' module
Type: enhancement Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 3.0
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: LambertDW, aronacher, benjamin.peterson, bhy, collinwinter, georg.brandl, sjt
Priority: normal Keywords:

Created on 2008-05-17 12:30 by bhy, last changed 2010-08-22 00:18 by georg.brandl. This issue is now closed.

Messages (7)
msg66993 - (view) Author: Haoyu Bai (bhy) Date: 2008-05-17 12:30
Functions like find() rfind() index() rindex() has been removed in
Python 3.0. So there should be a 2to3 fix for it.

Eg. fix
  if string.find(s, "hello") >= 0:
  if str.find(s, "hello") >= 0:

Thank you!
msg77320 - (view) Author: David W. Lambert (LambertDW) Date: 2008-12-08 16:19
I expect the answer will be that 2to3 cannot know what sort of object
"string" names.  Bell's theorem, or some such, as I understand it, tells
us that you must execute the algorithm to find out what it does, there
isn't a short cut.

It does seem like 2to3 could assume that you write code with honorable
intention, grace, and style and thereby offer a suggestive note.  The
string module is not an isolated case for such notices.  I made a
similar request to yours for "file" which is gone in version 3.

Unfortunately, code as follows is probably frequent, so we aren't likely
to get support for this feature.  Maybe here is an opportunity for
venture capital!

def f(list):
        argument should be a list.
        "list" in this scope no longer names __builtins__.list
msg77329 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-12-08 17:01
2to3 could handle it, but it would be a lot of work for something
unnecessary.  You can use "s.replace(a, b)" instead of string.replace(s,
a, b) since at least 2.0.
msg77330 - (view) Author: David W. Lambert (LambertDW) Date: 2008-12-08 17:10
I think the point is to get a message from 2to3 about possible use of
feature that is gone.  Of course python3 raises an exception when trying
to execute the code, but it does leave the user wondering "why did 2to3
report that there are no changes necessary?".
msg81960 - (view) Author: Stephen J. Turnbull (sjt) * (Python triager) Date: 2009-02-13 18:33
Maybe 2to3 could get a --pedantic or even an --annoying option?  I agree 
that it should be noisy about removed features even if actually fixing 
this kind of thing would be hard to do reliably.
msg81966 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2009-02-13 19:22
I disagree. That is the role of -3 warnings. Static analysis is too
limited to get into issuing warnings with.
msg114622 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-08-22 00:18
I guess this will not happen then.
Date User Action Args
2019-12-31 16:49:19serhiy.storchakalinkissue39172 superseder
2010-08-22 00:18:24georg.brandlsetstatus: open -> closed

nosy: + georg.brandl
messages: + msg114622

resolution: wont fix
2009-02-13 19:22:25benjamin.petersonsetassignee: collinwinter ->
messages: + msg81966
nosy: + benjamin.peterson
2009-02-13 18:33:05sjtsetnosy: + sjt
messages: + msg81960
2008-12-08 17:10:54LambertDWsetmessages: + msg77330
2008-12-08 17:01:48aronachersetmessages: + msg77329
2008-12-08 16:19:21LambertDWsetnosy: + LambertDW
messages: + msg77320
2008-12-08 15:04:20aronachersetnosy: + aronacher
2008-05-17 17:05:13benjamin.petersonsettitle: Fixes find, rfind, etc in 'string' module -> Fixers find, rfind, etc in 'string' module
2008-05-17 12:30:16bhycreate