Skip to content

Commit

Permalink
Merge pull request #420 from python/bugfix/419
Browse files Browse the repository at this point in the history
Declare Distribution as an abstract class.
  • Loading branch information
jaraco authored Jan 1, 2023
2 parents 4a4f062 + 2d52ecd commit d66e35a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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

0 comments on commit d66e35a

Please sign in to comment.