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

 
 

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

Submitted by:  None
Submitted on:  Mon 18 Aug 2014 11:08:15 PM UTC  
Votes:  50  
 
Category: NoneSeverity: 3 - Normal
Item Group: NoneStatus: Wont Fix
Privacy: PublicAssigned to: Eric S. Raymond <esr>
Open/Closed: Closed

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

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>
Project AdministratorIn charge of this item.
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>
Project AdministratorIn charge of this item.
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 File(s):
   
   
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
  • -unavailable- added by crappylogins (Updated the item)
  • -unavailable- added by esr (Posted a comment)
  • -unavailable- added by crappylogins (Voted in favor of this item)
  •  

    Do you think this task is very important?
    If so, you can click here to add your encouragement to it.
    This task has 50 encouragements so far.

    Only logged-in users can vote.

     

    Please enter the title of George Orwell's famous dystopian book (it's a date):

     

     

    Follow 7 latest changes.

    Date Changed By Updated Field Previous Value => Replaced By
    Wed 27 Aug 2014 09:24:33 AM UTCcrappyloginsAttached File-=>Added NotWorking.py, #31979
      Attached File-=>Added Workaround.py, #31980
      Attached File-=>Added Working.py, #31981
    Sat 23 Aug 2014 05:46:11 PM UTCesrOpen/ClosedOpen=>Closed
    Wed 20 Aug 2014 06:53:02 PM UTCesrStatusNone=>Wont Fix
      Assigned toNone=>esr
    Mon 18 Aug 2014 11:47:13 PM UTCcrappyloginsCarbon-Copy-=>Added crappylogins

    Back to the top


    Powered by Savane 3.1-cleanup1