Skip to content

Commit

Permalink
Remove the ABC from Distribution. Fixes #422.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Apr 14, 2023
1 parent b0cce8a commit 36eb89d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 6 additions & 6 deletions importlib_metadata/__init__.py
Expand Up @@ -31,7 +31,7 @@
from importlib import import_module
from importlib.abc import MetaPathFinder
from itertools import starmap
from typing import List, Mapping, Optional
from typing import List, Mapping, Optional, cast


__all__ = [
Expand Down Expand Up @@ -348,23 +348,22 @@ def __repr__(self):
return f'<FileHash mode: {self.mode} value: {self.value}>'


class Distribution(metaclass=abc.ABCMeta):
class Distribution:
"""A Python distribution package."""

@abc.abstractmethod
def read_text(self, filename):
def read_text(self, filename) -> Optional[str]:
"""Attempt to load metadata file given by the name.
:param filename: The name of the file in the distribution info.
:return: The text if found, otherwise None.
"""

@abc.abstractmethod
def locate_file(self, path):
"""
Given a path to a file in this distribution, return a path
to it.
"""
raise NotImplementedError

@classmethod
def from_name(cls, name: str):
Expand Down Expand Up @@ -426,14 +425,15 @@ def metadata(self) -> _meta.PackageMetadata:
The returned object will have keys that name the various bits of
metadata. See PEP 566 for details.
"""
text = (
opt_text = (
self.read_text('METADATA')
or self.read_text('PKG-INFO')
# This last clause is here to support old egg-info files. Its
# effect is to just end up using the PathDistribution's self._path
# (which points to the egg-info file) attribute unchanged.
or self.read_text('')
)
text = cast(str, opt_text)
return _adapters.Message(email.message_from_string(text))

@property
Expand Down
4 changes: 0 additions & 4 deletions tests/test_main.py
Expand Up @@ -44,10 +44,6 @@ def test_package_not_found_mentions_metadata(self):

assert "metadata" in str(ctx.exception)

def test_abc_enforced(self):
with self.assertRaises(TypeError):
type('DistributionSubclass', (Distribution,), {})()

@fixtures.parameterize(
dict(name=None),
dict(name=''),
Expand Down

0 comments on commit 36eb89d

Please sign in to comment.