Skip to content

Commit 8a64305

Browse files
authored
Switch from SelectableGroups to hasattr for importlib.metadata branching (#61) (#62)
`SelectableGroups` is no longer in python 3.12 and the original reason for this design was the lack of support for `hasattr` for mypy, which has since been resolved.
1 parent fecb244 commit 8a64305

2 files changed

Lines changed: 2 additions & 11 deletions

File tree

catalogue/__init__.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,6 @@
77
except ImportError:
88
from . import _importlib_metadata as importlib_metadata # type: ignore
99

10-
try: # Python 3.10
11-
from importlib.metadata import SelectableGroups # type: ignore
12-
except ImportError:
13-
14-
class _NotImplemented:
15-
pass
16-
17-
SelectableGroups = _NotImplemented # type: ignore
18-
1910
# Only ever call this once for performance reasons
2011
AVAILABLE_ENTRY_POINTS = importlib_metadata.entry_points() # type: ignore
2112

@@ -148,7 +139,7 @@ def get_entry_point(self, name: str, default: Optional[Any] = None) -> Any:
148139
return default
149140

150141
def _get_entry_points(self) -> List[importlib_metadata.EntryPoint]:
151-
if isinstance(AVAILABLE_ENTRY_POINTS, SelectableGroups):
142+
if hasattr(AVAILABLE_ENTRY_POINTS, "select"):
152143
return AVAILABLE_ENTRY_POINTS.select(group=self.entry_point_namespace)
153144
else: # dict
154145
return AVAILABLE_ENTRY_POINTS.get(self.entry_point_namespace, [])

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
zipp>=0.5; python_version < "3.8"
22
typing-extensions>=3.6.4; python_version < "3.8"
33
pytest>=4.6.5
4-
mypy>=0.991,<1.1.0
4+
mypy>=0.991,<1.1.0

0 commit comments

Comments
 (0)