File tree Expand file tree Collapse file tree 2 files changed +19
-0
lines changed
Expand file tree Collapse file tree 2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -183,6 +183,14 @@ def __getitem__(self, group) -> EntryPoints:
183183 def groups (self ):
184184 return set (ep .group for ep in self )
185185
186+ def get (self , group , default = None ):
187+ """
188+ For backward compatibility, supply .get
189+ """
190+ msg = "GroupedEntryPoints.get is deprecated. Just use __getitem__."
191+ warnings .warn (msg , DeprecationWarning )
192+ return self [group ] or default
193+
186194
187195class PackagePath (pathlib .PurePosixPath ):
188196 """A reference to a path in a package"""
Original file line number Diff line number Diff line change @@ -104,6 +104,17 @@ def test_entry_points_dict_construction(self):
104104 assert expected .category is DeprecationWarning
105105 assert "Construction of dict of EntryPoints is deprecated" in str (expected )
106106
107+ def test_entry_points_groups_get (self ):
108+ """
109+ Prior versions of entry_points() returned a dict. Ensure
110+ that callers using '.get()' are supported but warned to
111+ migrate.
112+ """
113+ with warnings .catch_warnings (record = True ):
114+ entry_points ().get ('missing' , 'default' ) == 'default'
115+ entry_points ().get ('entries' , 'default' ) == entry_points ()['entries' ]
116+ entry_points ().get ('missing' , ()) == entry_points ()['missing' ]
117+
107118 def test_metadata_for_this_package (self ):
108119 md = metadata ('egginfo-pkg' )
109120 assert md ['author' ] == 'Steven Ma'
You can’t perform that action at this time.
0 commit comments