[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gpsd-dev] [PATCH 1/4] Fixes gps/*.py to use new-style classes.
From: |
Fred Wright |
Subject: |
[gpsd-dev] [PATCH 1/4] Fixes gps/*.py to use new-style classes. |
Date: |
Sun, 10 Apr 2016 19:29:05 -0700 |
Although this isn't strictly a Python 3 requirement, using the
new-style class definition syntax improves consistency between Python
2 and Python 3. Old-style classes have been deprecated since Python
2.2, but many such definitions linger on. Python 3 eliminates
old-style classes, but instead of complaining about old-style
definitions, it simply unconditionally and silently makes all classes
new-style. The only incompatible differences are quite subtle and
rarely matter in practice, but things are more consistent across
versions if the new-style definitions are used.
Also, the preferred method for subclasses to invoke parent init
methods is via the super() construct, which is only available with
new-style classes. Using super() is especially useful with multiple
inheritance, which it handles automatically (provided that the init
methods have compatible signatures).
TESTED:
Ran "scons build-all check valgrind-audit", as well as gegps, gpscat,
gpsprof, xgps, and xgpsspeed, with all six supported Python versions
(except 2.6 for xgps*).
---
gps/client.py | 6 +++---
gps/fake.py | 8 ++++----
gps/gps.py | 4 ++--
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/gps/client.py b/gps/client.py
index 88d8054..3825bcf 100644
--- a/gps/client.py
+++ b/gps/client.py
@@ -11,7 +11,7 @@ from .misc import polystr, polybytes
GPSD_PORT = "2947"
-class gpscommon:
+class gpscommon(object):
"Isolate socket handling and buffering from the protocol interpretation."
def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0):
@@ -134,7 +134,7 @@ WATCH_PPS = 0x002000 # enable PPS in raw/NMEA
WATCH_DEVICE = 0x000800 # watch specific device
-class gpsjson:
+class gpsjson(object):
"Basic JSON decoding."
def __iter__(self):
@@ -193,7 +193,7 @@ class gpsjson:
return self.send(arg + "}")
-class dictwrapper:
+class dictwrapper(object):
"Wrapper that yields both class and dictionary behavior,"
def __init__(self, ddict):
diff --git a/gps/fake.py b/gps/fake.py
index 88336d3..aa6db17 100644
--- a/gps/fake.py
+++ b/gps/fake.py
@@ -125,7 +125,7 @@ class TestLoadError(BaseException):
self.msg = msg
-class TestLoad:
+class TestLoad(object):
"Digest a logfile into a list of sentences we can cycle through."
def __init__(self, logfp, predump=False, slow=False, oneshot=False):
@@ -221,7 +221,7 @@ class PacketError(BaseException):
self.msg = msg
-class FakeGPS:
+class FakeGPS(object):
def __init__(self, testload, progress=None):
self.testload = testload
self.progress = progress
@@ -436,7 +436,7 @@ class DaemonError(BaseException):
return repr(self.msg)
-class DaemonInstance:
+class DaemonInstance(object):
"Control a gpsd instance."
def __init__(self, control_socket=None):
@@ -558,7 +558,7 @@ class TestSessionError(BaseException):
self.msg = msg
-class TestSession:
+class TestSession(object):
"Manage a session including a daemon with fake GPSes and clients."
def __init__(self, prefix=None, port=None, options=None, verbose=0,
predump=False, udp=False, tcp=False, slow=False):
diff --git a/gps/gps.py b/gps/gps.py
index bc66f7c..a0868af 100755
--- a/gps/gps.py
+++ b/gps/gps.py
@@ -87,7 +87,7 @@ WATCH_NEWSTYLE = 0x010000 # force JSON streaming
WATCH_OLDSTYLE = 0x020000 # force old-style streaming
-class gpsfix:
+class gpsfix(object):
def __init__(self):
self.mode = MODE_NO_FIX
self.time = NaN
@@ -105,7 +105,7 @@ class gpsfix:
self.epc = NaN
-class gpsdata:
+class gpsdata(object):
"Position, track, velocity and status information returned by a GPS."
class satellite:
--
2.8.1
- [gpsd-dev] [PATCH 1/4] Fixes gps/*.py to use new-style classes.,
Fred Wright <=