Commit c99abaf8 authored by Jason R. Coombs's avatar Jason R. Coombs

Re-implement EntryPoint not as a namedtuple, avoiding the behaviors that implies.

parent 031c7f0e
Pipeline #99784731 passed with stages
in 4 minutes and 23 seconds
......@@ -10,7 +10,6 @@ import zipp
import operator
import functools
import itertools
import collections
from ._compat import (
install,
......@@ -27,7 +26,6 @@ from ._compat import (
ModuleNotFoundError,
MetaPathFinder,
email_message_from_string,
PyPy_repr,
)
from importlib import import_module
from itertools import starmap
......@@ -54,9 +52,7 @@ class PackageNotFoundError(ModuleNotFoundError):
"""The package was not found."""
class EntryPoint(
PyPy_repr,
collections.namedtuple('EntryPointBase', 'name value group')):
class EntryPoint:
"""An entry point as defined by Python packaging conventions.
See `the packaging docs on entry points
......@@ -85,6 +81,34 @@ class EntryPoint(
following the attr, and following any extras.
"""
__slots__ = 'name', 'value', 'group',
_fields = __slots__
def __init__(self, name, value, group):
super(EntryPoint, self).__setattr__('name', name)
super(EntryPoint, self).__setattr__('value', value)
super(EntryPoint, self).__setattr__('group', group)
def __setattr__(self, name, value):
raise AttributeError("can't set attribute")
def __eq__(self, other):
return (
self.name == other.name and
self.value == other.value and
self.group == other.group
)
def __hash__(self):
return hash((self.name, self.value, self.group))
def __repr__(self):
def make_param(name):
value = getattr(self, name)
return '{name}={value!r}'.format(**locals())
params = ', '.join(map(make_param, self._fields))
return 'EntryPoint({params})'.format(**locals())
def load(self):
"""Load the entry point from its definition. If only a module
is indicated by the value, return that module. Otherwise,
......
......@@ -113,25 +113,3 @@ email_message_from_string = (
# https://bitbucket.org/pypy/pypy/issues/3021/ioopen-directory-leaks-a-file-descriptor
PYPY_OPEN_BUG = getattr(sys, 'pypy_version_info', (9, 9, 9))[:3] <= (7, 1, 1)
class PyPy_repr:
"""
Override repr for EntryPoint objects on PyPy2 to avoid __iter__ access.
Ref #97.
"""
affected = (
hasattr(sys, 'pypy_version_info') and
sys.version_info < (3,)
)
def __compat_repr__(self): # pragma: nocover
def make_param(name):
value = getattr(self, name)
return '{name}={value!r}'.format(**locals())
params = ', '.join(map(make_param, self._fields))
return 'EntryPoint({params})'.format(**locals())
if affected: # pragma: nocover
__repr__ = __compat_repr__
del affected
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment