Skip to content

Commit ab33995

Browse files
committed
Remove compatibility code.
1 parent 107f902 commit ab33995

File tree

7 files changed

+17
-141
lines changed

7 files changed

+17
-141
lines changed

importlib_metadata/__init__.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,29 @@
1-
from __future__ import unicode_literals, absolute_import
2-
31
import io
42
import os
53
import re
64
import abc
75
import csv
86
import sys
97
import zipp
8+
import email
9+
import pathlib
1010
import operator
1111
import functools
1212
import itertools
1313
import posixpath
1414
import collections
1515

16+
from configparser import ConfigParser
17+
from contextlib import suppress
18+
from importlib import import_module
19+
from importlib.abc import MetaPathFinder
20+
from itertools import starmap
21+
1622
from ._compat import (
1723
install,
1824
NullFinder,
19-
ConfigParser,
20-
suppress,
21-
map,
22-
FileNotFoundError,
23-
IsADirectoryError,
24-
NotADirectoryError,
25-
PermissionError,
26-
pathlib,
27-
ModuleNotFoundError,
28-
MetaPathFinder,
29-
email_message_from_string,
3025
PyPy_repr,
31-
unique_ordered,
32-
str,
3326
)
34-
from importlib import import_module
35-
from itertools import starmap
36-
37-
38-
__metaclass__ = type
3927

4028

4129
__all__ = [
@@ -277,7 +265,7 @@ def metadata(self):
277265
# (which points to the egg-info file) attribute unchanged.
278266
or self.read_text('')
279267
)
280-
return email_message_from_string(text)
268+
return email.message_from_string(text)
281269

282270
@property
283271
def version(self):
@@ -457,7 +445,7 @@ def zip_children(self):
457445
names = zip_path.root.namelist()
458446
self.joinpath = zip_path.joinpath
459447

460-
return unique_ordered(
448+
return dict.fromkeys(
461449
child.split(posixpath.sep, 1)[0]
462450
for child in names
463451
)

importlib_metadata/_compat.py

Lines changed: 1 addition & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,7 @@
1-
from __future__ import absolute_import, unicode_literals
2-
3-
import io
4-
import abc
51
import sys
6-
import email
7-
8-
9-
if sys.version_info > (3,): # pragma: nocover
10-
import builtins
11-
from configparser import ConfigParser
12-
import contextlib
13-
FileNotFoundError = builtins.FileNotFoundError
14-
IsADirectoryError = builtins.IsADirectoryError
15-
NotADirectoryError = builtins.NotADirectoryError
16-
PermissionError = builtins.PermissionError
17-
map = builtins.map
18-
from itertools import filterfalse
19-
else: # pragma: nocover
20-
from backports.configparser import ConfigParser
21-
from itertools import imap as map # type: ignore
22-
from itertools import ifilterfalse as filterfalse
23-
import contextlib2 as contextlib
24-
FileNotFoundError = IOError, OSError
25-
IsADirectoryError = IOError, OSError
26-
NotADirectoryError = IOError, OSError
27-
PermissionError = IOError, OSError
28-
29-
str = type('')
30-
31-
suppress = contextlib.suppress
32-
33-
if sys.version_info > (3, 5): # pragma: nocover
34-
import pathlib
35-
else: # pragma: nocover
36-
import pathlib2 as pathlib
37-
38-
try:
39-
ModuleNotFoundError = builtins.FileNotFoundError
40-
except (NameError, AttributeError): # pragma: nocover
41-
ModuleNotFoundError = ImportError # type: ignore
42-
43-
44-
if sys.version_info >= (3,): # pragma: nocover
45-
from importlib.abc import MetaPathFinder
46-
else: # pragma: nocover
47-
class MetaPathFinder(object):
48-
__metaclass__ = abc.ABCMeta
492

503

51-
__metaclass__ = type
52-
__all__ = [
53-
'install', 'NullFinder', 'MetaPathFinder', 'ModuleNotFoundError',
54-
'pathlib', 'ConfigParser', 'map', 'suppress', 'FileNotFoundError',
55-
'NotADirectoryError', 'email_message_from_string',
56-
]
4+
__all__ = ['install', 'NullFinder', 'PyPy_repr']
575

586

597
def install(cls):
@@ -104,20 +52,6 @@ def find_spec(*args, **kwargs):
10452
find_module = find_spec
10553

10654

107-
def py2_message_from_string(text): # nocoverpy3
108-
# Work around https://bugs.python.org/issue25545 where
109-
# email.message_from_string cannot handle Unicode on Python 2.
110-
io_buffer = io.StringIO(text)
111-
return email.message_from_file(io_buffer)
112-
113-
114-
email_message_from_string = (
115-
py2_message_from_string
116-
if sys.version_info < (3,) else
117-
email.message_from_string
118-
)
119-
120-
12155
class PyPy_repr:
12256
"""
12357
Override repr for EntryPoint objects on PyPy to avoid __iter__ access.
@@ -135,18 +69,3 @@ def make_param(name):
13569
if affected: # pragma: nocover
13670
__repr__ = __compat_repr__
13771
del affected
138-
139-
140-
# from itertools recipes
141-
def unique_everseen(iterable): # pragma: nocover
142-
"List unique elements, preserving order. Remember all elements ever seen."
143-
seen = set()
144-
seen_add = seen.add
145-
146-
for element in filterfalse(seen.__contains__, iterable):
147-
seen_add(element)
148-
yield element
149-
150-
151-
unique_ordered = (
152-
unique_everseen if sys.version_info < (3, 7) else dict.fromkeys)

tests/fixtures.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,12 @@
1-
from __future__ import unicode_literals
2-
31
import os
42
import sys
53
import shutil
4+
import pathlib
65
import tempfile
76
import textwrap
7+
import contextlib
88
import test.support
99

10-
from importlib_metadata._compat import pathlib, contextlib
11-
12-
13-
__metaclass__ = type
14-
1510

1611
@contextlib.contextmanager
1712
def tempdir():

tests/test_api.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,6 @@
88
entry_points, files, metadata, requires, version,
99
)
1010

11-
try:
12-
from collections.abc import Iterator
13-
except ImportError:
14-
from collections import Iterator # noqa: F401
15-
16-
try:
17-
from builtins import str as text
18-
except ImportError:
19-
from __builtin__ import unicode as text
20-
2111

2212
class APITests(
2313
fixtures.EggInfoPkg,
@@ -29,12 +19,12 @@ class APITests(
2919

3020
def test_retrieves_version_of_self(self):
3121
pkg_version = version('egginfo-pkg')
32-
assert isinstance(pkg_version, text)
22+
assert isinstance(pkg_version, str)
3323
assert re.match(self.version_pattern, pkg_version)
3424

3525
def test_retrieves_version_of_distinfo_pkg(self):
3626
pkg_version = version('distinfo-pkg')
37-
assert isinstance(pkg_version, text)
27+
assert isinstance(pkg_version, str)
3828
assert re.match(self.version_pattern, pkg_version)
3929

4030
def test_for_name_does_not_exist(self):

tests/test_integration.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,3 @@
1-
# coding: utf-8
2-
3-
from __future__ import unicode_literals
4-
51
import unittest
62
import packaging.requirements
73
import packaging.version

tests/test_main.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# coding: utf-8
2-
from __future__ import unicode_literals
3-
41
import re
52
import json
63
import pickle
@@ -17,18 +14,13 @@
1714
entry_points, metadata, version,
1815
)
1916

20-
try:
21-
from builtins import str as text
22-
except ImportError:
23-
from __builtin__ import unicode as text
24-
2517

2618
class BasicTests(fixtures.DistInfoPkg, unittest.TestCase):
2719
version_pattern = r'\d+\.\d+(\.\d)?'
2820

2921
def test_retrieves_version_of_self(self):
3022
dist = Distribution.from_name('distinfo-pkg')
31-
assert isinstance(dist.version, text)
23+
assert isinstance(dist.version, str)
3224
assert re.match(self.version_pattern, dist.version)
3325

3426
def test_for_name_does_not_exist(self):

tests/test_zip.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22
import unittest
33

4+
from contextlib import ExitStack
45
from importlib_metadata import (
56
distribution, entry_points, files, PackageNotFoundError,
67
version, distributions,
@@ -13,11 +14,6 @@
1314
except (ImportError, AttributeError):
1415
import importlib_resources as resources
1516

16-
try:
17-
from contextlib import ExitStack
18-
except ImportError:
19-
from contextlib2 import ExitStack
20-
2117

2218
class TestZip(unittest.TestCase):
2319
root = 'tests.data'

0 commit comments

Comments
 (0)