bpo-15450: Allow subclassing of filecmp.dircmp by NickCrews · Pull Request #23424 · python/cpython (original) (raw)
Currently, the subdirs attribute of filecmp.dircmp does not respect subclassing:
from filecmp import dircmp
class MyDirCmp(dircmp):
... pass
...
my_dcmp = MyDirCmp('dir1', 'dir2')
for item in my_dcmp.subdirs.values():
... print(type(item))
... break
...
<class 'filecmp.dircmp'>
This is the only place where dircmp does not respect subclassing. It can be corrected here:
def phase4(self): # Find out differences between common subdirectories
...
...
self.subdirs[x] = dircmp(a_x, b_x, self.ignore, self.hide)
This would let one do things like override dircmp.report() and have dircmp.report_full_closure() behave as expected, or replace the phaseN()
methods with your custom behavior and have that work for all
subdirectories.
Co-authored-by: Chris Jerdonek chris.jerdonek@gmail.com