bpo-39481: PEP 585 for difflib, filecmp, fileinput (#19422)

This commit is contained in:
Ethan Smith 2020-04-09 21:47:31 -07:00 committed by GitHub
parent 7c4185d62d
commit e3ec44d692
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 0 deletions

View file

@ -32,6 +32,7 @@
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 @@ def real_quick_ratio(self):
# 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.

View file

@ -13,6 +13,7 @@
import os
import stat
from itertools import filterfalse
from types import GenericAlias
__all__ = ['clear_cache', 'cmp', 'dircmp', 'cmpfiles', 'DEFAULT_IGNORES']
@ -247,6 +248,9 @@ def __getattr__(self, attr):
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.

View file

@ -73,6 +73,7 @@
"""
import sys, os
from types import GenericAlias
__all__ = ["input", "close", "nextfile", "filename", "lineno", "filelineno",
"fileno", "isfirstline", "isstdin", "FileInput", "hook_compressed",
@ -391,6 +392,8 @@ def isfirstline(self):
def isstdin(self):
return self._isstdin
__class_getitem__ = classmethod(GenericAlias)
def hook_compressed(filename, mode):
ext = os.path.splitext(filename)[1]

View file

@ -7,6 +7,9 @@
)
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 @@ def test_subscriptable(self):
for t in (type, tuple, list, dict, set, frozenset, enumerate,
mmap,
defaultdict, deque,
SequenceMatcher,
dircmp,
FileInput,
OrderedDict, Counter, UserDict, UserList,
Pattern, Match,
AbstractContextManager, AbstractAsyncContextManager,