bpo-39481: PEP 585 for difflib, filecmp, fileinput (#19422) · python/cpython@e3ec44d (original) (raw)

4 files changed

lines changed

Original file line number Diff line number Diff line change
@@ -32,6 +32,7 @@
32 32
33 33 from heapq import nlargest as _nlargest
34 34 from collections import namedtuple as _namedtuple
35 +from types import GenericAlias
35 36
36 37 Match = _namedtuple('Match', 'a b size')
37 38
@@ -685,6 +686,9 @@ def real_quick_ratio(self):
685 686 # shorter sequence
686 687 return _calculate_ratio(min(la, lb), la + lb)
687 688
689 +__class_getitem__ = classmethod(GenericAlias)
690 +
691 +
688 692 def get_close_matches(word, possibilities, n=3, cutoff=0.6):
689 693 """Use SequenceMatcher to return list of the best "good enough" matches.
690 694
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@
13 13 import os
14 14 import stat
15 15 from itertools import filterfalse
16 +from types import GenericAlias
16 17
17 18 __all__ = ['clear_cache', 'cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES']
18 19
@@ -247,6 +248,9 @@ def __getattr__(self, attr):
247 248 self.methodmap[attr](self)
248 249 return getattr(self, attr)
249 250
251 +__class_getitem__ = classmethod(GenericAlias)
252 +
253 +
250 254 def cmpfiles(a, b, common, shallow=True):
251 255 """Compare common files in two directories.
252 256
Original file line number Diff line number Diff line change
@@ -73,6 +73,7 @@
73 73 """
74 74
75 75 import sys, os
76 +from types import GenericAlias
76 77
77 78 __all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno",
78 79 "fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed",
@@ -391,6 +392,8 @@ def isfirstline(self):
391 392 def isstdin(self):
392 393 return self._isstdin
393 394
395 +__class_getitem__ = classmethod(GenericAlias)
396 +
394 397
395 398 def hook_compressed(filename, mode):
396 399 ext = os.path.splitext(filename)[1]
Original file line number Diff line number Diff line change
@@ -7,6 +7,9 @@
7 7 )
8 8 from collections.abc import *
9 9 from contextlib import AbstractContextManager, AbstractAsyncContextManager
10 +from difflib import SequenceMatcher
11 +from filecmp import dircmp
12 +from fileinput import FileInput
10 13 from mmap import mmap
11 14 from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
12 15 from itertools import chain
@@ -25,6 +28,9 @@ def test_subscriptable(self):
25 28 for t in (type, tuple, list, dict, set, frozenset, enumerate,
26 29 mmap,
27 30 defaultdict, deque,
31 +SequenceMatcher,
32 +dircmp,
33 +FileInput,
28 34 OrderedDict, Counter, UserDict, UserList,
29 35 Pattern, Match,
30 36 AbstractContextManager, AbstractAsyncContextManager,