Skip to content

Commit 83e879d

Browse files
committed
Add DeprecationWarning when use_statcache argument is supplied
Fix use of GetoptError, so demo() now works
1 parent 98b922c commit 83e879d

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

Lib/filecmp.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
dircmp
55
66
Functions:
7-
cmp(f1, f2, shallow=1, use_statcache=0) -> int
7+
cmp(f1, f2, shallow=1) -> int
88
cmpfiles(a, b, common) -> ([], [], [])
99
1010
"""
1111

1212
import os
1313
import stat
14+
import warnings
1415

1516
__all__ = ["cmp","dircmp","cmpfiles"]
1617

1718
_cache = {}
1819
BUFSIZE=8*1024
1920

20-
def cmp(f1, f2, shallow=1, use_statcache=0):
21+
def cmp(f1, f2, shallow=1, use_statcache=None):
2122
"""Compare two files.
2223
2324
Arguments:
@@ -39,6 +40,10 @@ def cmp(f1, f2, shallow=1, use_statcache=0):
3940
with a cache invalidation mechanism relying on stale signatures.
4041
4142
"""
43+
if use_statcache is not None:
44+
warnings.warn("use_statcache argument is deprecated",
45+
DeprecationWarning)
46+
4247
s1 = _sig(os.stat(f1))
4348
s2 = _sig(os.stat(f2))
4449
if s1[0] != stat.S_IFREG or s2[0] != stat.S_IFREG:
@@ -261,7 +266,7 @@ def report_full_closure(self): # Report on self and subdirs recursively
261266
sd.report_full_closure()
262267

263268

264-
def cmpfiles(a, b, common, shallow=1, use_statcache=0):
269+
def cmpfiles(a, b, common, shallow=1, use_statcache=None):
265270
"""Compare common files in two directories.
266271
267272
a, b -- directory names
@@ -275,6 +280,9 @@ def cmpfiles(a, b, common, shallow=1, use_statcache=0):
275280
filenames that aren't regular files.
276281
277282
"""
283+
if use_statcache is not None:
284+
warnings.warn("use_statcache argument is deprecated",
285+
DeprecationWarning)
278286
res = ([], [], [])
279287
for x in common:
280288
ax = os.path.join(a, x)
@@ -312,7 +320,7 @@ def demo():
312320
import getopt
313321
options, args = getopt.getopt(sys.argv[1:], 'r')
314322
if len(args) != 2:
315-
raise getopt.error, 'need exactly two args'
323+
raise getopt.GetoptError('need exactly two args', None)
316324
dd = dircmp(args[0], args[1])
317325
if ('-r', '') in options:
318326
dd.report_full_closure()

0 commit comments

Comments
 (0)