From 2f2f9d0b5c96e68ed91cddd6673860ee752eb49c Mon Sep 17 00:00:00 2001 From: Nick Crews Date: Mon, 23 Nov 2020 09:29:37 -0700 Subject: bpo-15450: Allow subclassing of dircmp (GH-23424) (#23424) Co-authored-by: Chris Jerdonek --- Lib/filecmp.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'Lib/filecmp.py') diff --git a/Lib/filecmp.py b/Lib/filecmp.py index 7a4da6beb50..7c47eb022cc 100644 --- a/Lib/filecmp.py +++ b/Lib/filecmp.py @@ -115,7 +115,9 @@ class dircmp: same_files: list of identical files. diff_files: list of filenames which differ. funny_files: list of files which could not be compared. - subdirs: a dictionary of dircmp objects, keyed by names in common_dirs. + subdirs: a dictionary of dircmp instances (or MyDirCmp instances if this + object is of type MyDirCmp, a subclass of dircmp), keyed by names + in common_dirs. """ def __init__(self, a, b, ignore=None, hide=None): # Initialize @@ -185,14 +187,15 @@ class dircmp: self.same_files, self.diff_files, self.funny_files = xx def phase4(self): # Find out differences between common subdirectories - # A new dircmp object is created for each common subdirectory, + # A new dircmp (or MyDirCmp if dircmp was subclassed) object is created + # for each common subdirectory, # these are stored in a dictionary indexed by filename. # The hide and ignore properties are inherited from the parent self.subdirs = {} for x in self.common_dirs: a_x = os.path.join(self.left, x) b_x = os.path.join(self.right, x) - self.subdirs[x] = dircmp(a_x, b_x, self.ignore, self.hide) + self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide) def phase4_closure(self): # Recursively call phase4() on subdirectories self.phase4() -- cgit v1.2.3