Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Declare Distribution as an abstract class. #420

Merged
merged 3 commits into from Jan 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGES.rst
@@ -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
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
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