cpython icon indicating copy to clipboard operation
cpython copied to clipboard

filecmp.dircmp does not allow non-shallow comparisons

Open 70016164-7717-4b4e-bfab-f9063e654a22 opened this issue 14 years ago • 16 comments

BPO 12932
Nosy @terryjreedy, @rbtcollins, @merwok, @regebro, @mitar, @cjerdonek
Files
  • issue12932.diff: Add input parameter 'shallow' to dircmp.
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2011-09-07.16:01:35.750>
    labels = ['type-feature', 'library']
    title = 'filecmp.dircmp does not allow non-shallow comparisons'
    updated_at = <Date 2018-01-03.09:42:28.161>
    user = 'https://bugs.python.org/kesmit'
    

    bugs.python.org fields:

    activity = <Date 2018-01-03.09:42:28.161>
    actor = 'mitar'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2011-09-07.16:01:35.750>
    creator = 'kesmit'
    dependencies = []
    files = ['30589']
    hgrepos = []
    issue_num = 12932
    keywords = ['patch']
    message_count = 9.0
    messages = ['143692', '156736', '160966', '161823', '164648', '166246', '191154', '247695', '247696']
    nosy_count = 8.0
    nosy_names = ['terry.reedy', 'rbcollins', 'eric.araujo', 'lregebro', 'mitar', 'chris.jerdonek', 'planet36', 'kesmit']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue12932'
    versions = ['Python 3.6']
    

    Linked PRs

    • gh-109499
    • gh-121767
    • gh-121777

    While filecmp.cmp and filecmp.cmpfiles allow a shallow option to be specified to invoke a more involved comparison of files, filecmp.dircmp does not. It is limited to shallow-only comparisons.

    This could be solved quite easily by adding a shallow keyword option to dircmp then changing the phase3 method to the following.

        def phase3(self): # Find out differences between common files
            xx = cmpfiles(self.left, self.right, self.common_files, self.shallow)
            self.same_files, self.diff_files, self.funny_files = xx
    

    Thanks for the report. Unfortunately 2.7 is closed to new features and the module is removed in 3.x, so there is nothing to do here.

    merwok avatar Mar 25 '12 06:03 merwok

    filecmp is still there in Python 3.3 Alpha 3. I can't find any reference to it being deprecated.

    Lennart, I saw your response on StackOverflow ;-).

    terryjreedy avatar May 29 '12 00:05 terryjreedy

    +1 for this.

    Whether or not this feature is implemented, I think the documentation should state that directory comparisons are done using "shallow=True". I created bpo-15250 for this.

    cjerdonek avatar Jul 04 '12 14:07 cjerdonek

    Allowing dircmp() to accept a file comparison function is another option to consider that may address more needs going forward. shallow=False could be achieved by passing lambda a, b: filecmp.cmp(a, b, shallow=False).

    cjerdonek avatar Jul 23 '12 19:07 cjerdonek

    Add input parameter 'shallow' to dircmp. Use it in phase3 and phase4. Document it in filecmp.rst.

    Did not modify test_filecmp.py.

    Thanks for the patch @planet36, however I think this is sufficiently large a change that we should also have a test case for it.

    I'm also retargeting this to the current open branches for feature work - 3.6.

    rbtcollins avatar Jul 30 '15 20:07 rbtcollins

    Bah, wrong stage. patch review.

    rbtcollins avatar Jul 30 '15 20:07 rbtcollins

    @rbtcollins any update here?

    jnm27 avatar Nov 17 '22 20:11 jnm27

    You can see that the latest comment is from 2015.

    Someone would need to take the patch, apply it to Python main branch, make sure tests, docs and changelog are present, and open a pull request. The devguide has help about that.

    merwok avatar Nov 17 '22 21:11 merwok

    Thanks to everyone involved!

    encukou avatar Mar 06 '24 13:03 encukou

    Really wish github would send a notif on the issue when a PR is created to solve it!

    merwok avatar Mar 06 '24 14:03 merwok

    Not a bad idea. Did bpo do so? (I cannot remember either way for sure.)

    Given the absence of such notices, the PR author should have requested a review from you. If not already, the devguide should say something about looking for participants (preferably recent) who are members of 'Python' or 'python/core'. (bpo starred our names on comments.)

    terryjreedy avatar Mar 07 '24 01:03 terryjreedy

    Should the new parameter be made keyword-only? I feel we usually do that for newly added optional parameters. We have a little bit of time left before the RC phase to change this.

    JelleZijlstra avatar Jul 13 '24 20:07 JelleZijlstra

    Submitted #121767 to make the new parameter keyword-only.

    JelleZijlstra avatar Jul 14 '24 13:07 JelleZijlstra

    It looks like everything is done here, for real this time!

    ZeroIntensity avatar Jan 11 '25 17:01 ZeroIntensity