bugGPSD - Bugs: bug #43021, gps.py breaks build-in time...

 
 

bug #43021: gps.py breaks build-in time function of python

Submitter:  None
Submitted:  Mon 18 Aug 2014 11:08:15 PM UTC
Votes: 50
 
Category:  None Severity:  3 - Normal
Item Group:  None Status:  Wont Fix
Privacy:  Public Assigned to:  esr
Open/Closed:  Closed
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 28 Aug 2014 01:54:03 PM UTC, comment #3: 

I don't understand why you think you need to use "from import" and create these collisions.  Why not "import gps" and leave everything (including the defines) safely in its own namespace?

Until I hear a very convincing reason that you can't do this, I'm not going to do anything to destablize the existing interface.

Eric S. Raymond <esr>
Group administrator
Wed 27 Aug 2014 09:24:33 AM UTC, comment #2: 

I put the examples in the text but if You prefer it as attached files,i attatch them here.

Regarding bug or not. Sure You can say it works as designed. But I do not agree that it is a well design. The many many defines in the GPS module more or less forces mme to use "import *", which often lead to name collisions like this. And it is hard to se because You do not know what names You import.

I attached a workaround.py, but You will se if I need more than the oe define it will also start to get ugly.

A simple and elegant solution as i suggested is to add those defines to the gps class that way i can just "import gps"
and use gps.WATCH_ENABLE

(file #31979, file #31980, file #31981)

Martin Otzen <crappylogins>
Wed 20 Aug 2014 06:53:02 PM UTC, comment #1: 

This is not a bug in the GPSD code.  It is an expected feature of Python.  You should call the time function as time.time().

If you attach the example code that isn't working for you, perhaps I can help you fix it.

Eric S. Raymond <esr>
Group administrator
Mon 18 Aug 2014 11:08:15 PM UTC, original submission:  

line 6 in misc.py breaks the build in time function, when using gps.py as in the examples.


Try this
-------------------
from time import time # For delays
#from gps import *

print time
print time()
-----------------------
output:
<built-in function time>
1408401515.16

now uncomment the second line
-------------------
from time import time # For delays
from gps import *

print time
print time()
-----------------------
output:
<module 'time' (built-in)>
Traceback (most recent call last):
  File "/home/martin/src/gps-bug.py", line 3, in <module>
    print time()
TypeError: 'module' object is not callable

One workaround is to do this
--------------------
from time import time # For delays
from gps import gps, WATCH_ENABLE


print time
print time()
------------------
This would alow be to use this function:
 gpsd = gps(mode=WATCH_ENABLE)

But I would have to explicitly import every symbol i need, getting ugly.

A better solution is for gps.py to pack the defines in a class, like this:
class gpssetup:
    ONLINE_SET         = (1<<1)
    TIME_SET           = (1<<2)
    TIMERR_SET         = (1<<3)
    LATLON_SET         = (1<<4)
    ALTITUDE_SET       = (1<<5)
    SPEED_SET          = (1<<6)
    TRACK_SET          = (1<<7)

This would alow be to use this function:
------------------
from time import time # For delays
from gps import gps, gpssetup

gpsd = gps(mode=gpssetup.WATCH_ENABLE)

------------------

Or as I prefer add the defines to the gps class alowing this
------------------
from time import time # For delays
from gps import gps

gpsd = gps(mode=gps.WATCH_ENABLE)

------------------

NB: this is the second time I write this bug report, first time i wrote it entered the title og orells novel, but apparantly it should not be the title as written on the cover of his book (acording to wikipedia) in letters but the number the the letter spell. To I was presented with an error followed by a nice clean form, ready to start all over.

Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #31979:  NotWorking.py added by crappylogins (112B - text/x-python)
file #31980:  Workaround.py added by crappylogins (350B - text/x-python)
file #31981:  Working.py added by crappylogins (108B - text/x-python)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by crappylogins (Updated the item)
  • -email is unavailable- added by esr (Posted a comment)
  • -email is unavailable- added by crappylogins (Voted in favor of this item)
  •  

    There are 50 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only logged-in users can vote.

     

    Follow 7 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-08-27 crappylogins Attached File- Added NotWorking.py, #31979
        Attached File- Added Workaround.py, #31980
        Attached File- Added Working.py, #31981
    2014-08-23 esr Open/ClosedOpen Closed
    2014-08-20 esr StatusNone Wont Fix
        Assigned toNone esr
    2014-08-18 crappylogins Carbon-Copy- Added crappylogins

    Back to the top

    Powered by Savane 3.13-4448.
    Corresponding source code