Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
v6.0.0
======

* #419: Declared ``Distribution`` as an abstract class, enforcing
definition of abstract methods in instantiated subclasses. It's no
longer possible to instantiate a ``Distribution`` or any subclasses
unless they define the abstract methods.

Please comment in the issue if this change breaks any projects.
This change will likely be rolled back if it causes significant
disruption.

v5.2.0
======

Expand Down
2 changes: 1 addition & 1 deletion importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ def __repr__(self):
return f'<FileHash mode: {self.mode} value: {self.value}>'


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

@abc.abstractmethod
Expand Down
4 changes: 4 additions & 0 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ 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