Skip to content

Commit

Permalink
Switch from SelectableGroups to hasattr for importlib.metadata branch…
Browse files Browse the repository at this point in the history
…ing (#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.
  • Loading branch information
adrianeboyd committed Jul 24, 2023
1 parent fecb244 commit 8a64305
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
11 changes: 1 addition & 10 deletions catalogue/__init__.py
Expand Up @@ -7,15 +7,6 @@
except ImportError:
from . import _importlib_metadata as importlib_metadata # type: ignore

try: # Python 3.10
from importlib.metadata import SelectableGroups # type: ignore
except ImportError:

class _NotImplemented:
pass

SelectableGroups = _NotImplemented # type: ignore

# Only ever call this once for performance reasons
AVAILABLE_ENTRY_POINTS = importlib_metadata.entry_points() # type: ignore

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

def _get_entry_points(self) -> List[importlib_metadata.EntryPoint]:
if isinstance(AVAILABLE_ENTRY_POINTS, SelectableGroups):
if hasattr(AVAILABLE_ENTRY_POINTS, "select"):
return AVAILABLE_ENTRY_POINTS.select(group=self.entry_point_namespace)
else: # dict
return AVAILABLE_ENTRY_POINTS.get(self.entry_point_namespace, [])
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
@@ -1,4 +1,4 @@
zipp>=0.5; python_version < "3.8"
typing-extensions>=3.6.4; python_version < "3.8"
pytest>=4.6.5
mypy>=0.991,<1.1.0
mypy>=0.991,<1.1.0

0 comments on commit 8a64305

Please sign in to comment.