summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEthan Smith <ethan@ethanhs.me>2020-04-10 04:47:31 (GMT)
committerGitHub <noreply@github.com>2020-04-10 04:47:31 (GMT)
commite3ec44d692d9442e640cf5b2d8708157a65cec3e (patch)
treedc16382cb3ae14abfda9fb38257202bb1ab7b3d2
parent7c4185d62d4aec486d82c3ad02acd878db2d3537 (diff)
downloadcpython-e3ec44d692d9442e640cf5b2d8708157a65cec3e.zip
cpython-e3ec44d692d9442e640cf5b2d8708157a65cec3e.tar.gz
cpython-e3ec44d692d9442e640cf5b2d8708157a65cec3e.tar.bz2
bpo-39481: PEP 585 for difflib, filecmp, fileinput (#19422)
-rw-r--r--Lib/difflib.py4
-rw-r--r--Lib/filecmp.py4
-rw-r--r--Lib/fileinput.py3
-rw-r--r--Lib/test/test_genericalias.py6
4 files changed, 17 insertions, 0 deletions
diff --git a/Lib/difflib.py b/Lib/difflib.py
index 5d75643..f2215d8 100644
--- a/Lib/difflib.py
+++ b/Lib/difflib.py
@@ -32,6 +32,7 @@ __all__ = ['get_close_matches', 'ndiff', 'restore', 'SequenceMatcher',
from heapq import nlargest as _nlargest
from collections import namedtuple as _namedtuple
+from types import GenericAlias
Match = _namedtuple('Match', 'a b size')
@@ -685,6 +686,9 @@ class SequenceMatcher:
# shorter sequence
return _calculate_ratio(min(la, lb), la + lb)
+ __class_getitem__ = classmethod(GenericAlias)
+
+
def get_close_matches(word, possibilities, n=3, cutoff=0.6):
"""Use SequenceMatcher to return list of the best "good enough" matches.
diff --git a/Lib/filecmp.py b/Lib/filecmp.py
index cfdca1e..7a4da6b 100644
--- a/Lib/filecmp.py
+++ b/Lib/filecmp.py
@@ -13,6 +13,7 @@ Functions:
import os
import stat
from itertools import filterfalse
+from types import GenericAlias
__all__ = ['clear_cache', 'cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES']
@@ -247,6 +248,9 @@ class dircmp:
self.methodmap[attr](self)
return getattr(self, attr)
+ __class_getitem__ = classmethod(GenericAlias)
+
+
def cmpfiles(a, b, common, shallow=True):
"""Compare common files in two directories.
diff --git a/Lib/fileinput.py b/Lib/fileinput.py
index c1b0ec9..0c31f93 100644
--- a/Lib/fileinput.py
+++ b/Lib/fileinput.py
@@ -73,6 +73,7 @@ XXX Possible additions:
"""
import sys, os
+from types import GenericAlias
__all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno",
"fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed",
@@ -391,6 +392,8 @@ class FileInput:
def isstdin(self):
return self._isstdin
+ __class_getitem__ = classmethod(GenericAlias)
+
def hook_compressed(filename, mode):
ext = os.path.splitext(filename)[1]
diff --git a/Lib/test/test_genericalias.py b/Lib/test/test_genericalias.py
index 196b059..4241eab 100644
--- a/Lib/test/test_genericalias.py
+++ b/Lib/test/test_genericalias.py
@@ -7,6 +7,9 @@ from collections import (
)
from collections.abc import *
from contextlib import AbstractContextManager, AbstractAsyncContextManager
+from difflib import SequenceMatcher
+from filecmp import dircmp
+from fileinput import FileInput
from mmap import mmap
from ipaddress import IPv4Network, IPv4Interface, IPv6Network, IPv6Interface
from itertools import chain
@@ -25,6 +28,9 @@ class BaseTest(unittest.TestCase):
for t in (type, tuple, list, dict, set, frozenset, enumerate,
mmap,
defaultdict, deque,
+ SequenceMatcher,
+ dircmp,
+ FileInput,
OrderedDict, Counter, UserDict, UserList,
Pattern, Match,
AbstractContextManager, AbstractAsyncContextManager,