[Git][reproducible-builds/diffoscope][master] 3 commits: Drop explicit inheriting from 'object' class; unnecessary in Python 3.

Chris Lamb gitlab at salsa.debian.org
Wed Sep 25 13:54:02 UTC 2019



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
7c21ed37 by Chris Lamb at 2019-09-25T13:47:13Z
Drop explicit inheriting from 'object' class; unnecessary in Python 3.

- - - - -
e066e77c by Chris Lamb at 2019-09-25T13:53:31Z
Drop an unnecessary "pass" statement.

- - - - -
ff57b860 by Chris Lamb at 2019-09-25T13:53:33Z
Drop some unnecessary control flow.

- - - - -


22 changed files:

- diffoscope/changes.py
- diffoscope/comparators/__init__.py
- diffoscope/comparators/directory.py
- diffoscope/comparators/ffprobe.py
- diffoscope/comparators/gettext.py
- diffoscope/comparators/utils/archive.py
- diffoscope/comparators/utils/command.py
- diffoscope/comparators/utils/container.py
- diffoscope/comparators/utils/file.py
- diffoscope/comparators/utils/libarchive.py
- diffoscope/comparators/zip.py
- diffoscope/config.py
- diffoscope/diff.py
- diffoscope/difference.py
- diffoscope/main.py
- diffoscope/presenters/formats.py
- diffoscope/presenters/html/html.py
- diffoscope/presenters/utils.py
- diffoscope/profiling.py
- diffoscope/progress.py
- diffoscope/readers/json.py
- diffoscope/tools.py


Changes:

=====================================
diffoscope/changes.py
=====================================
@@ -57,7 +57,7 @@ class ChangesFileException(Exception):
     pass
 
 
-class Changes(object):
+class Changes:
     """
     Changes object to help process and store information regarding Debian
     .changes files, used in the upload process.
@@ -224,8 +224,8 @@ class Changes(object):
         """
         if '/' in section:
             return section.split('/')
-        else:
-            return ['main', section]
+
+        return ['main', section]
 
     def set_directory(self, directory):
         if directory:


=====================================
diffoscope/comparators/__init__.py
=====================================
@@ -30,7 +30,7 @@ from ..logging import line_eraser
 logger = logging.getLogger(__name__)
 
 
-class ComparatorManager(object):
+class ComparatorManager:
     COMPARATORS = (
         ('directory.Directory',),
         ('missing_file.MissingFile',),


=====================================
diffoscope/comparators/directory.py
=====================================
@@ -191,7 +191,7 @@ def compare_directories(path1, path2, source=None):
     return FilesystemDirectory(path1).compare(FilesystemDirectory(path2))
 
 
-class Directory(object):
+class Directory:
     DESCRIPTION = "directories"
 
     @classmethod


=====================================
diffoscope/comparators/ffprobe.py
=====================================
@@ -48,7 +48,7 @@ class Ffprobe(Command):
     def filter(self, line):
         if self.flag:
             return line
-        elif line == b'  Metadata:\n':
+        if line == b'  Metadata:\n':
             self.flag = True
         return b''
 


=====================================
diffoscope/comparators/gettext.py
=====================================
@@ -60,11 +60,12 @@ class Msgunfmt(Command):
                     .encode('utf-8')
                 )
             return b''
-        if self._encoding != 'utf-8':
-            return line.decode(self._encoding).encode('utf-8')
-        else:
+
+        if self._encoding == 'utf-8':
             return line
 
+        return line.decode(self._encoding).encode('utf-8')
+
 
 class MoFile(File):
     DESCRIPTION = "Gettext message catalogues"


=====================================
diffoscope/comparators/utils/archive.py
=====================================
@@ -36,8 +36,7 @@ class Archive(Container, metaclass=abc.ABCMeta):
     def __new__(cls, source, *args, **kwargs):
         if isinstance(source, MissingFile):
             return super(Container, MissingArchive).__new__(MissingArchive)
-        else:
-            return super(Container, cls).__new__(cls)
+        return super(Container, cls).__new__(cls)
 
     def __init__(self, *args, **kwargs):
         super().__init__(*args, **kwargs)
@@ -122,7 +121,7 @@ class ArchiveMember(File):
         return False
 
 
-class MissingArchiveLikeObject(object):
+class MissingArchiveLikeObject:
     def getnames(self):
         return []
 


=====================================
diffoscope/comparators/utils/command.py
=====================================
@@ -25,7 +25,7 @@ import subprocess
 logger = logging.getLogger(__name__)
 
 
-class Command(object, metaclass=abc.ABCMeta):
+class Command(metaclass=abc.ABCMeta):
     MAX_STDERR_LINES = 50
 
     def __init__(self, path):


=====================================
diffoscope/comparators/utils/container.py
=====================================
@@ -39,7 +39,7 @@ NO_COMMENT = None
 logger = logging.getLogger(__name__)
 
 
-class Container(object, metaclass=abc.ABCMeta):
+class Container(metaclass=abc.ABCMeta):
     auto_diff_metadata = True
 
     def __new__(cls, source):


=====================================
diffoscope/comparators/utils/file.py
=====================================
@@ -64,7 +64,7 @@ def _run_tests(fold, tests):
     return fold(t(y, x) for x, t, y in tests)
 
 
-class File(object, metaclass=abc.ABCMeta):
+class File(metaclass=abc.ABCMeta):
     if hasattr(magic, 'open'):  # use Magic-file-extensions from file
 
         @classmethod


=====================================
diffoscope/comparators/utils/libarchive.py
=====================================
@@ -278,9 +278,9 @@ class LibarchiveContainer(Archive):
     def get_subclass(self, entry):
         if entry.isdir:
             return LibarchiveDirectory(self, entry)
-        elif entry.issym:
+        if entry.issym:
             return LibarchiveSymlink(self, entry)
-        elif entry.isblk or entry.ischr:
+        if entry.isblk or entry.ischr:
             return LibarchiveDevice(self, entry)
 
         return LibarchiveMember(self, entry)


=====================================
diffoscope/comparators/zip.py
=====================================
@@ -191,7 +191,7 @@ class ZipFile(File):
         return differences
 
 
-class IgnoreReturncodeMixin(object):
+class IgnoreReturncodeMixin:
     @property
     def returncode(self):
         returncode = super().returncode


=====================================
diffoscope/config.py
=====================================
@@ -31,7 +31,7 @@ class defaultint(int):
 
 # Avoid setting values on this anywhere other than main.run_diffoscope(),
 # otherwise tests may fail unpredictably depending on order-of-execution.
-class Config(object):
+class Config:
     _singleton = {}
 
     def __init__(self):


=====================================
diffoscope/diff.py
=====================================
@@ -40,7 +40,7 @@ logger = logging.getLogger(__name__)
 re_diff_change = re.compile(r'^([+-@]).*', re.MULTILINE)
 
 
-class DiffParser(object):
+class DiffParser:
     RANGE_RE = re.compile(
         # example: '@@ -26814,9 +26814,8 @@'
         rb'''
@@ -265,8 +265,6 @@ class _Feeder:
     (currently?) instances of any particular class.
     """
 
-    pass
-
 
 def empty_file_feeder():
     """
@@ -507,7 +505,7 @@ def linediff_simplify(g):
         yield current
 
 
-class SideBySideDiff(object):
+class SideBySideDiff:
     """Calculates a side-by-side diff from a unified diff."""
 
     def __init__(self, unified_diff, diffon=DIFFON, diffoff=DIFFOFF):


=====================================
diffoscope/difference.py
=====================================
@@ -29,7 +29,7 @@ from .excludes import command_excluded
 logger = logging.getLogger(__name__)
 
 
-class Difference(object):
+class Difference:
     def __init__(
         self,
         unified_diff,
@@ -357,7 +357,7 @@ class Difference(object):
         self._size_cache = None
 
 
-class VisualDifference(object):
+class VisualDifference:
     def __init__(self, data_type, content, source):
         self._data_type = data_type
         self._content = content


=====================================
diffoscope/main.py
=====================================
@@ -499,7 +499,7 @@ class HelpFormatter(argparse.HelpFormatter):
         return val
 
 
-class RangeCompleter(object):
+class RangeCompleter:
     def __init__(self, start, end=0, divisions=16):
         if end < start:
             tmp = end


=====================================
diffoscope/presenters/formats.py
=====================================
@@ -30,7 +30,7 @@ from .restructuredtext import RestructuredTextPresenter
 logger = logging.getLogger(__name__)
 
 
-class PresenterManager(object):
+class PresenterManager:
     _singleton = {}
 
     def __init__(self):


=====================================
diffoscope/presenters/html/html.py
=====================================
@@ -369,7 +369,7 @@ class HTMLPrintContext(
         return None if self.single_page else self.target
 
 
-class HTMLSideBySidePresenter(object):
+class HTMLSideBySidePresenter:
     supports_visual_diffs = True
 
     def __init__(self):
@@ -467,34 +467,32 @@ class HTMLSideBySidePresenter(object):
             if self.spl_rows >= self.max_lines_parent:
                 raise DiffBlockLimitReached()
             return False
-        else:
-            # html-dir output, perhaps need to rotate
-            if self.spl_rows >= self.max_lines:
-                raise DiffBlockLimitReached()
 
-            if self.spl_current_page == 0:  # on parent page
-                if self.spl_rows < self.max_lines_parent:
-                    return False
-                logger.debug(
-                    "new unified-diff subpage, parent page went over %s lines",
-                    self.max_lines_parent,
-                )
-            else:  # on child page
-                if (
-                    self.bytes_max_total
-                    and self.bytes_written > self.bytes_max_total
-                ):
-                    raise PrintLimitReached()
-                if (
-                    self.spl_print_func.bytes_written
-                    < self.max_page_size_child
-                ):
-                    return False
-                logger.debug(
-                    "new unified-diff subpage, previous subpage went over %s bytes",
-                    self.max_page_size_child,
-                )
-            return True
+        # html-dir output, perhaps need to rotate
+        if self.spl_rows >= self.max_lines:
+            raise DiffBlockLimitReached()
+
+        if self.spl_current_page == 0:  # on parent page
+            if self.spl_rows < self.max_lines_parent:
+                return False
+            logger.debug(
+                "new unified-diff subpage, parent page went over %s lines",
+                self.max_lines_parent,
+            )
+        else:  # on child page
+            if (
+                self.bytes_max_total
+                and self.bytes_written > self.bytes_max_total
+            ):
+                raise PrintLimitReached()
+            if self.spl_print_func.bytes_written < self.max_page_size_child:
+                return False
+            logger.debug(
+                "new unified-diff subpage, previous subpage went over %s bytes",
+                self.max_page_size_child,
+            )
+
+        return True
 
     def new_child_page(self):
         _, rotation_params = self.spl_print_ctrl
@@ -689,15 +687,15 @@ class HTMLPresenter(Presenter):
         del continuations[node]
 
     def output_node_placeholder(self, pagename, lazy_load, size=0):
-        if lazy_load:
-            return templates.DIFFNODE_LAZY_LOAD % {
-                "pagename": pagename,
-                "pagesize": sizeof_fmt(Config().max_page_size_child),
-                "size": sizeof_fmt(size),
-            }
-        else:
+        if not lazy_load:
             return templates.DIFFNODE_LIMIT
 
+        return templates.DIFFNODE_LAZY_LOAD % {
+            "pagename": pagename,
+            "pagesize": sizeof_fmt(Config().max_page_size_child),
+            "size": sizeof_fmt(size),
+        }
+
     def output_difference(self, ctx, root_difference):
         outputs = {}  # nodes to their partial output
         ancestors = {}  # child nodes to ancestor nodes


=====================================
diffoscope/presenters/utils.py
=====================================
@@ -44,7 +44,7 @@ def sizeof_fmt(num, suffix='B', sigfig=3):
     return "%s %s%s" % (round_sigfig(num, sigfig), unit, suffix)
 
 
-class Presenter(object):
+class Presenter:
     supports_visual_diffs = False
 
     def __init__(self):
@@ -146,7 +146,7 @@ class PartialFormatter(string.Formatter):
     parse_no_escape = string.Formatter.parse
 
 
-class FormatPlaceholder(object):
+class FormatPlaceholder:
     def __init__(self, ident):
         self.ident = str(ident)
 
@@ -166,7 +166,7 @@ class FormatPlaceholder(object):
         return FormatPlaceholder(self.ident + "." + str(attr))
 
 
-class PartialString(object):
+class PartialString:
     r"""A format string where the "holes" are indexed by arbitrary python
     objects instead of string names or integer indexes. This is useful when you
     need to compose these objects together, but don't want users of the partial
@@ -404,8 +404,7 @@ class PartialString(object):
         def cont(t, fmtstr, *holes):
             if isinstance(fmtstr, cls):
                 return t.pformat({cont: fmtstr})
-            else:
-                return t.pformat({cont: cls(fmtstr, *(holes + (cont,)))})
+            return t.pformat({cont: cls(fmtstr, *(holes + (cont,)))})
 
         return cls("{0}", cont), cont
 


=====================================
diffoscope/profiling.py
=====================================
@@ -34,7 +34,7 @@ def profile(namespace, key):
         ProfileManager().increment(start, namespace, key)
 
 
-class ProfileManager(object):
+class ProfileManager:
     _singleton = {}
 
     def __init__(self):


=====================================
diffoscope/progress.py
=====================================
@@ -46,7 +46,7 @@ class ProgressLoggingHandler(logging.StreamHandler):
             self.handleError(record)
 
 
-class ProgressManager(object):
+class ProgressManager:
     _singleton = {}
 
     def __init__(self):
@@ -120,7 +120,7 @@ class ProgressManager(object):
             x.finish()
 
 
-class Progress(object):
+class Progress:
     def __init__(self, total=None):
         self.done = []
         self.current_steps = None
@@ -196,7 +196,7 @@ class Progress(object):
         self.current_child_steps_done += total
 
 
-class ProgressBar(object):
+class ProgressBar:
     def __init__(self):
         import progressbar
 
@@ -269,7 +269,7 @@ class ProgressBar(object):
         self.bar.finish()
 
 
-class StatusFD(object):
+class StatusFD:
     def __init__(self, fileobj):
         self.fileobj = fileobj
 


=====================================
diffoscope/readers/json.py
=====================================
@@ -25,7 +25,7 @@ from ..presenters.json import JSON_FORMAT_MAGIC
 from .utils import UnrecognizedFormatError
 
 
-class JSONReaderV1(object):
+class JSONReaderV1:
     def load(self, fp, fn):
         # fp should be a str-stream not a bytes-stream. If you need to pass in
         # a bytes-stream, wrap it in codecs.getreader('utf-8')(fp)


=====================================
diffoscope/tools.py
=====================================
@@ -122,10 +122,9 @@ def get_current_os():
 
 
 def get_current_distro_like():
-    if distro:
-        return distro.like().split()
-    else:
+    if not distro:
         return []
+    return distro.like().split()
 
 
 def get_package_provider(tool, os=None):



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/1351fdd46f031e4886c4aa10a5423aef46c39a07...ff57b8607f9c33053928ef2a2bebbf05a1ba9b51

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/compare/1351fdd46f031e4886c4aa10a5423aef46c39a07...ff57b8607f9c33053928ef2a2bebbf05a1ba9b51
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20190925/cc2a64a5/attachment.html>


More information about the rb-commits mailing list