-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-15450: Allow subclassing of filecmp.dircmp #23424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello, and thanks for your contribution! I'm a bot set up to make sure that the project can legally accept this contribution by verifying everyone involved has signed the PSF contributor agreement (CLA). CLA MissingOur records indicate the following people have not signed the CLA: For legal reasons we need all the people listed to sign the CLA before we can look at your contribution. Please follow the steps outlined in the CPython devguide to rectify this issue. If you have recently signed the CLA, please wait at least one business day You can check yourself to see if the CLA has been received. Thanks again for the contribution, we look forward to reviewing it! |
CLA signing is pending... |
I force pushed to fix a typo on windows for case-insensitive file names. |
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>
Added |
# 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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use type(self)
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really any good reason, I was copying @cjerdonek's patch and that's what he used. They evaluate to the same thing, right? I believe in Python 2 we would have needed to use .__class__
, but now there is not that restriction. You're just thinking of style?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same thing I guess, both variants are equal.
@asvetlov: Please replace |
Thanks! |
Co-authored-by: Chris Jerdonek <chris.jerdonek@gmail.com>
Currently, the subdirs attribute of filecmp.dircmp does not respect subclassing:
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
https://bugs.python.org/issue15450