FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[3.13] gh-57141: Make shallow argument to filecmp.dircmp keyword-only (GH-121767) by miss-islington · Pull Request #121777 · python/cpython · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (2) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 1 addition & 1 deletion Doc/library/filecmp.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ The :mod:`filecmp` module defines the following functions:
The :class:`dircmp` class
-------------------------

.. class:: dircmp(a, b, ignore=None, hide=None, shallow=True)
.. class:: dircmp(a, b, ignore=None, hide=None, *, shallow=True)

Construct a new directory comparison object, to compare the directories *a*
and *b*. *ignore* is a list of names to ignore, and defaults to
Expand Down
6 changes: 3 additions & 3 deletions Lib/filecmp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def _do_cmp(f1, f2):
class dircmp:
"""A class that manages the comparison of 2 directories.

dircmp(a, b, ignore=None, hide=None, shallow=True)
dircmp(a, b, ignore=None, hide=None, *, shallow=True)
A and B are directories.
IGNORE is a list of names to ignore,
defaults to DEFAULT_IGNORES.
Expand Down Expand Up @@ -124,7 +124,7 @@ class dircmp:
in common_dirs.
"""

def __init__(self, a, b, ignore=None, hide=None, shallow=True): # Initialize
def __init__(self, a, b, ignore=None, hide=None, *, shallow=True): # Initialize
self.left = a
self.right = b
if hide is None:
Expand Down Expand Up @@ -201,7 +201,7 @@ def phase4(self): # Find out differences between common subdirectories
a_x = os.path.join(self.left, x)
b_x = os.path.join(self.right, x)
self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide,
self.shallow)
shallow=self.shallow)

def phase4_closure(self): # Recursively call phase4() on subdirectories
self.phase4()
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_filecmp.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import filecmp
import os
import re
import shutil
import tempfile
import unittest
Expand Down Expand Up @@ -277,6 +278,17 @@ def test_dircmp_shallow_same_file(self):
]
self._assert_report(d.report, expected_report)

def test_dircmp_shallow_is_keyword_only(self):
with self.assertRaisesRegex(
TypeError,
re.escape("dircmp.__init__() takes from 3 to 5 positional arguments but 6 were given"),
):
filecmp.dircmp(self.dir, self.dir_same, None, None, True)
self.assertIsInstance(
filecmp.dircmp(self.dir, self.dir_same, None, None, shallow=True),
filecmp.dircmp,
)

def test_dircmp_subdirs_type(self):
"""Check that dircmp.subdirs respects subclassing."""
class MyDirCmp(filecmp.dircmp):
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The *shallow* argument to :class:`filecmp.dircmp` (new in Python 3.13) is
now keyword-only.

Back | FazBrowse Home | New Git URL