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.

classification
Title: 2to3 converts long(itude) argument to int
Type: Stage:
Components: 2to3 (2.x to 3.x conversion tool) Versions: Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: benjamin.peterson Nosy List: aronacher, benjamin.peterson, collinwinter, crmccreary, eric-talevich, georg.brandl, maubp, retoo, robin.stocker
Priority: normal Keywords:

Created on 2008-05-01 19:20 by crmccreary, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
long_fixer_bug.py eric-talevich, 2010-07-23 03:54 Test script in Python 2: "long" as a function argument
Messages (9)
msg66038 - (view) Author: Charles McCreary (crmccreary) Date: 2008-05-01 19:20
The 2to3 converter converts variables named "long" to "int".
Original:
long is an argument (longitude)
def add_test_qtrmin(tdb, lat, long, area_id, call_center=""):

Converted:

def add_test_qtrmin(tdb, lat, int, area_id, call_center=""):

I can see what it is trying to do, but I definitely don't want this
behavior!
msg66041 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008-05-01 20:43
Agreed. There's code in fix_next to detect this kind of case. I'll see
what I can do about generalizing it to support fix_long.
msg66048 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-05-01 21:18
This seems to happen whenever argument are types that need to be renamed
(eg. unicode -> str) Can this be fixed globally?
msg66051 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2008-05-01 21:45
It *could* be implemented for all fixers, but since it's fairly
expensive, I'd rather limit it to cases where the problem is more likely
to occur (for example, unicode -> str doesn't meet this threshold IMHO).
msg66949 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2008-05-16 15:29
Let me note that this also happens for assignments like:

long = Type("long", "l")
msg77300 - (view) Author: Armin Ronacher (aronacher) * (Python committer) Date: 2008-12-08 12:18
This could probably be fixed by adding a `is_builtin` helper function to
the fixer_util module that checks if the name is not overriden in the
module.  I would use something like a weak dictionary for the
`find_binding` function because that could turn out to be quite expensive.

Besides long this is probably also useful for `reduce` and some others.
msg77544 - (view) Author: Reto Schüttel (retoo) Date: 2008-12-10 14:44
This is even worse in case of attributes (like in pyephem for the
observer object):


  class Foo(object):
      def __init__(self):
          self.long = 1
          
  x = Foo()
  print x.long


2to3 produces:


--- attr.py (original)
+++ attr.py (refactored)
@@ -1,6 +1,6 @@
 class Foo(object):
     def __init__(self):
-        self.long = 1
+        self.int = 1
         
 x = Foo()
-print x.long
+print(x.int)


I think 2to3 shouldn't refactor any attribute names. I doubt anybody
would access the type long using an attribute :).

Cheers,
Reto
msg78641 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2008-12-31 17:56
I hope r68106 helps. 2to3 now refuses to change long if it is being
assigned to, the name of a function or class, the name of an argument,
or an attribute.
msg111241 - (view) Author: Eric Talevich (eric-talevich) Date: 2010-07-23 03:54
This issue still occurs when the name "long" is a function argument:

def double(long):
    return long * 2


2to3 converts it to:

def double(long):
    return int * 2


Should I file a new bug, or can someone reopen this?
History
Date User Action Args
2022-04-11 14:56:33adminsetgithub: 46986
2010-07-23 10:03:19maubpsetnosy: + maubp
2010-07-23 03:54:42eric-talevichsetfiles: + long_fixer_bug.py
versions: + Python 2.7, - Python 3.0
nosy: + eric-talevich

messages: + msg111241
2008-12-31 17:56:10benjamin.petersonsetstatus: open -> closed
resolution: fixed
messages: + msg78641
2008-12-10 18:28:30benjamin.petersonsetassignee: collinwinter -> benjamin.peterson
2008-12-10 14:45:10robin.stockersetnosy: + robin.stocker
2008-12-10 14:44:43retoosetnosy: + retoo
messages: + msg77544
2008-12-08 12:18:47aronachersetnosy: + aronacher
messages: + msg77300
2008-05-16 15:29:43georg.brandlsetnosy: + georg.brandl
messages: + msg66949
2008-05-01 21:45:29collinwintersetmessages: + msg66051
2008-05-01 21:18:47benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg66048
2008-05-01 20:43:25collinwintersetmessages: + msg66041
2008-05-01 19:20:59crmccrearycreate