Skip to content

Commit e3ec44d

Browse files
authored
bpo-39481: PEP 585 for difflib, filecmp, fileinput (#19422)
1 parent 7c4185d commit e3ec44d

File tree

4 files changed

+17
-0
lines changed

4 files changed

+17
-0
lines changed

Lib/difflib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
from heapq import nlargest as _nlargest
3434
from collections import namedtuple as _namedtuple
35+
from types import GenericAlias
3536

3637
Match = _namedtuple('Match', 'a b size')
3738

@@ -685,6 +686,9 @@ def real_quick_ratio(self):
685686
# shorter sequence
686687
return _calculate_ratio(min(la, lb), la + lb)
687688

689+
__class_getitem__ = classmethod(GenericAlias)
690+
691+
688692
def get_close_matches(word, possibilities, n=3, cutoff=0.6):
689693
"""Use SequenceMatcher to return list of the best "good enough" matches.
690694

Lib/filecmp.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import os
1414
import stat
1515
from itertools import filterfalse
16+
from types import GenericAlias
1617

1718
__all__ = ['clear_cache', 'cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES']
1819

@@ -247,6 +248,9 @@ def __getattr__(self, attr):
247248
self.methodmap[attr](self)
248249
return getattr(self, attr)
249250

251+
__class_getitem__ = classmethod(GenericAlias)
252+
253+
250254
def cmpfiles(a, b, common, shallow=True):
251255
"""Compare common files in two directories.
252256

Lib/fileinput.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
"""
7474

7575
import sys, os
76+
from types import GenericAlias
7677

7778
__all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno",
7879
"fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed",
@@ -391,6 +392,8 @@ def isfirstline(self):
391392
def isstdin(self):
392393
return self._isstdin
393394

395+
__class_getitem__ = classmethod(GenericAlias)
396+
394397

395398
def hook_compressed(filename, mode):
396399
ext = os.path.splitext(filename)[1]

Lib/test/test_genericalias.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
)
88
from collections.abc import *
99
from contextlib import AbstractContextManager, AbstractAsyncContextManager
10+
from difflib import SequenceMatcher
11+
from filecmp import dircmp
12+
from fileinput import FileInput
1013
from mmap import mmap
1114
from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
1215
from itertools import chain
@@ -25,6 +28,9 @@ def test_subscriptable(self):
2528
for t in (type, tuple, list, dict, set, frozenset, enumerate,
2629
mmap,
2730
defaultdict, deque,
31+
SequenceMatcher,
32+
dircmp,
33+
FileInput,
2834
OrderedDict, Counter, UserDict, UserList,
2935
Pattern, Match,
3036
AbstractContextManager, AbstractAsyncContextManager,

0 commit comments

Comments
 (0)