[Git][NTPsec/ntpsec][master] PEP8: clean up empty sequence checks

Matt Selsky gitlab at mg.gitlab.com
Mon Feb 25 01:12:31 UTC 2019


Matt Selsky pushed to branch master at NTPsec / ntpsec


Commits:
3f242e36 by Matt Selsky at 2019-02-25T01:09:18Z
PEP8: clean up empty sequence checks

For sequences, (strings, lists, tuples), use the fact that empty sequences are
false.

- - - - -


5 changed files:

- ntpclients/ntplogtemp.py
- ntpclients/ntpmon.py
- ntpclients/ntptrace.py
- ntpclients/ntpviz.py
- pylib/statfiles.py


Changes:

=====================================
ntpclients/ntplogtemp.py
=====================================
@@ -177,7 +177,7 @@ class Temper:
                 if args.verbose:
                     sys.stderr.write("TEMPer-poll failed\n")
 
-        if 0 == len(data):
+        if not data:
             self.has_temper = False
         return data
 


=====================================
ntpclients/ntpmon.py
=====================================
@@ -306,7 +306,7 @@ if __name__ == '__main__':
                     else:
                         peer_report.polls = [1]  # Kluge!
                         peers = []
-                    if showpeers and len(peers) == 0:
+                    if showpeers and not peers:
                         raise Fatal("no peers reported")
                     try:
                         initphase = False


=====================================
ntpclients/ntptrace.py
=====================================
@@ -51,7 +51,7 @@ def ntp_read_vars(peer, vars, host):
     obsolete = {'phase': 'offset',
                 'rootdispersion': 'rootdisp'}
 
-    if not len(vars):
+    if not vars:
         do_all = True
     else:
         do_all = False
@@ -149,7 +149,7 @@ for (switch, val) in options:
         print("ntptrace %s" % ntp.util.stdversion())
         raise SystemExit(0)
 
-if len(arguments):
+if arguments:
     host = arguments[0]
 
 hostcount = 0


=====================================
ntpclients/ntpviz.py
=====================================
@@ -139,7 +139,7 @@ class MyArgumentParser(argparse.ArgumentParser):
         arg_line = re.sub('\s+#.*$', '', arg_line)
 
         # ignore blank lines
-        if 0 == len(arg_line):
+        if not arg_line:
             return []
         # ignore comment lines
         if '#' == arg_line[0]:
@@ -257,7 +257,7 @@ class VizStats(ntp.statfiles.NTPStats):
             target = max(self.percs["p99"], -self.percs["p1"],
                          self.percs["p100"]/5, -self.percs["p0"]/5)
 
-        if len(units):
+        if units:
             # fixed scale
             self.multiplier = 1
             self.unit = units
@@ -393,7 +393,7 @@ def gnuplot_fmt(min_val, max_val):
 def gnuplot(template, outfile=None):
     "Run a specified gnuplot program."
 
-    if not len(template):
+    if not template:
         # silently ignore empty plots
         return ''
     if outfile is None:
@@ -511,7 +511,7 @@ set rmargin 10
 
     def local_offset_gnuplot(self):
         "Generate gnuplot code graphing local clock loop statistics"
-        if not len(self.loopstats):
+        if not self.loopstats:
             sys.stderr.write("ntpviz: WARNING: no loopstats to graph\n")
             return ''
 
@@ -574,14 +574,14 @@ file.</p>
 
     def local_freq_temps_plot(self):
         "Generate gnuplot code graphing local frequency and temps"
-        if not len(self.loopstats):
+        if not self.loopstats:
             sys.stderr.write("ntpviz: WARNING: no loopstats to graph\n")
             return ''
 
         tempsmap = self.tempssplit()
         tempslist = list(tempsmap.keys())
         tempslist.sort()
-        if not len(tempsmap) or not len(tempslist):
+        if not tempsmap or not tempslist:
             sys.stderr.write("ntpviz: WARNING: no temps to graph\n")
             return ''
 
@@ -672,7 +672,7 @@ file, and field 3 from the tempstats log file.</p>
         tempslist = list(tempsmap.keys())
         tempslist.sort()
 
-        if not len(tempsmap) or not len(tempslist):
+        if not tempsmap or not tempslist:
             sys.stderr.write("ntpviz: WARNING: no temps to graph\n")
             return ''
 
@@ -734,7 +734,7 @@ component of frequency drift.</p>
         gpslist = list(gpsmap.keys())
         gpslist.sort()
 
-        if not len(gpsmap) or not len(gpslist):
+        if not gpsmap or not gpslist:
             if 1 <= args.debug_level:
                 sys.stderr.write("ntpviz: INFO: no GPS data to graph\n")
             return ''
@@ -811,7 +811,7 @@ Greater than 20 means there will be significant inaccuracy and error.</p>
 
     def local_error_gnuplot(self):
         "Plot the local clock frequency error."
-        if not len(self.loopstats):
+        if not self.loopstats:
             sys.stderr.write("ntpviz: WARNING: no loopstats to graph\n")
             return ''
 


=====================================
pylib/statfiles.py
=====================================
@@ -202,7 +202,7 @@ class NTPStats:
     def peersplit(self):
         """Return a dictionary mapping peerstats IPs to entry subsets.
         This is very expensive, so cache the result"""
-        if len(self.peermap):
+        if self.peermap:
             return self.peermap
 
         for row in self.peerstats:



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3f242e360e5e825dd536dbc480f5765938939990

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/3f242e360e5e825dd536dbc480f5765938939990
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20190225/444cfda9/attachment-0001.html>


More information about the vc mailing list