Skip to content

Commit 99dd224

Browse files
committed
Deprecate dict construction from EntryPoint items.
1 parent b5081fa commit 99dd224

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

importlib_metadata/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import email
88
import pathlib
99
import operator
10+
import warnings
1011
import functools
1112
import itertools
1213
import posixpath
@@ -139,11 +140,12 @@ def _for(self, dist):
139140
def __iter__(self):
140141
"""
141142
Supply iter so one may construct dicts of EntryPoints by name.
142-
143-
>>> eps = [EntryPoint('a', 'b', 'c'), EntryPoint('d', 'e', 'f')]
144-
>>> dict(eps)['a']
145-
EntryPoint(name='a', value='b', group='c')
146143
"""
144+
msg = (
145+
"Construction of dict of EntryPoints is deprecated in "
146+
"favor of EntryPoints."
147+
)
148+
warnings.warn(msg, DeprecationWarning)
147149
return iter((self.name, self))
148150

149151
def __reduce__(self):

tests/test_api.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import re
22
import textwrap
33
import unittest
4+
import warnings
45

56
from . import fixtures
67
from importlib_metadata import (
@@ -88,10 +89,17 @@ def test_entry_points_dict_construction(self):
8889
allowed casting those lists into maps by name using ``dict()``.
8990
Capture this now deprecated use-case.
9091
"""
91-
eps = dict(entry_points()['entries'])
92+
with warnings.catch_warnings(record=True) as caught:
93+
eps = dict(entry_points()['entries'])
94+
9295
assert 'main' in eps
9396
assert eps['main'] == entry_points()['entries']['main']
9497

98+
# check warning
99+
expected = next(iter(caught))
100+
assert expected.category is DeprecationWarning
101+
assert "Construction of dict of EntryPoints is deprecated" in str(expected)
102+
95103
def test_metadata_for_this_package(self):
96104
md = metadata('egginfo-pkg')
97105
assert md['author'] == 'Steven Ma'

0 commit comments

Comments
 (0)