| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7982363 commit 50eec50
4 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -70,7 +70,7 @@ The :mod:`filecmp` module defines the following functions: | |||
| 70 | 70 | The :class:`dircmp` class | |
| 71 | 71 | ------------------------- | |
| 72 | 72 | ||
| 73 | - .. class:: dircmp(a, b, ignore=None, hide=None, shallow=True) | ||
| 73 | + .. class:: dircmp(a, b, ignore=None, hide=None, *, shallow=True) | ||
| 74 | 74 | ||
| 75 | 75 | Construct a new directory comparison object, to compare the directories *a* | |
| 76 | 76 | and *b*. *ignore* is a list of names to ignore, and defaults to | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -88,7 +88,7 @@ def _do_cmp(f1, f2): | |||
| 88 | 88 | class dircmp: | |
| 89 | 89 | """A class that manages the comparison of 2 directories. | |
| 90 | 90 | ||
| 91 | - dircmp(a, b, ignore=None, hide=None, shallow=True) | ||
| 91 | + dircmp(a, b, ignore=None, hide=None, *, shallow=True) | ||
| 92 | 92 | A and B are directories. | |
| 93 | 93 | IGNORE is a list of names to ignore, | |
| 94 | 94 | defaults to DEFAULT_IGNORES. | |
@@ -124,7 +124,7 @@ class dircmp: | |||
| 124 | 124 | in common_dirs. | |
| 125 | 125 | """ | |
| 126 | 126 | ||
| 127 | - def __init__(self, a, b, ignore=None, hide=None, shallow=True): # Initialize | ||
| 127 | + def __init__(self, a, b, ignore=None, hide=None, *, shallow=True): # Initialize | ||
| 128 | 128 | self.left = a | |
| 129 | 129 | self.right = b | |
| 130 | 130 | if hide is None: | |
@@ -201,7 +201,7 @@ def phase4(self): # Find out differences between common subdirectories | |||
| 201 | 201 | a_x = os.path.join(self.left, x) | |
| 202 | 202 | b_x = os.path.join(self.right, x) | |
| 203 | 203 | self.subdirs[x] = self.__class__(a_x, b_x, self.ignore, self.hide, | |
| 204 | - self.shallow) | ||
| 204 | + shallow=self.shallow) | ||
| 205 | 205 | ||
| 206 | 206 | def phase4_closure(self): # Recursively call phase4() on subdirectories | |
| 207 | 207 | self.phase4() | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,6 @@ | |||
| 1 | 1 | import filecmp | |
| 2 | 2 | import os | |
| 3 | + import re | ||
| 3 | 4 | import shutil | |
| 4 | 5 | import tempfile | |
| 5 | 6 | import unittest | |
@@ -277,6 +278,17 @@ def test_dircmp_shallow_same_file(self): | |||
| 277 | 278 | ] | |
| 278 | 279 | self._assert_report(d.report, expected_report) | |
| 279 | 280 | ||
| 281 | + def test_dircmp_shallow_is_keyword_only(self): | ||
| 282 | + with self.assertRaisesRegex( | ||
| 283 | + TypeError, | ||
| 284 | + re.escape("dircmp.__init__() takes from 3 to 5 positional arguments but 6 were given"), | ||
| 285 | + ): | ||
| 286 | + filecmp.dircmp(self.dir, self.dir_same, None, None, True) | ||
| 287 | + self.assertIsInstance( | ||
| 288 | + filecmp.dircmp(self.dir, self.dir_same, None, None, shallow=True), | ||
| 289 | + filecmp.dircmp, | ||
| 290 | + ) | ||
| 291 | + | ||
| 280 | 292 | def test_dircmp_subdirs_type(self): | |
| 281 | 293 | """Check that dircmp.subdirs respects subclassing.""" | |
| 282 | 294 | class MyDirCmp(filecmp.dircmp): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + The *shallow* argument to :class:`filecmp.dircmp` (new in Python 3.13) is | ||
| 2 | + now keyword-only. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments