Skip to content

Commit d66e35a

Browse files
authored
Merge pull request #420 from python/bugfix/419
Declare Distribution as an abstract class.
2 parents 4a4f062 + 2d52ecd commit d66e35a

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

CHANGES.rst

+12
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
v6.0.0
2+
======
3+
4+
* #419: Declared ``Distribution`` as an abstract class, enforcing
5+
definition of abstract methods in instantiated subclasses. It's no
6+
longer possible to instantiate a ``Distribution`` or any subclasses
7+
unless they define the abstract methods.
8+
9+
Please comment in the issue if this change breaks any projects.
10+
This change will likely be rolled back if it causes significant
11+
disruption.
12+
113
v5.2.0
214
======
315

importlib_metadata/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def __repr__(self):
346346
return f'<FileHash mode: {self.mode} value: {self.value}>'
347347

348348

349-
class Distribution:
349+
class Distribution(metaclass=abc.ABCMeta):
350350
"""A Python distribution package."""
351351

352352
@abc.abstractmethod

tests/test_main.py

+4
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ def test_package_not_found_mentions_metadata(self):
4343

4444
assert "metadata" in str(ctx.exception)
4545

46+
def test_abc_enforced(self):
47+
with self.assertRaises(TypeError):
48+
type('DistributionSubclass', (Distribution,), {})()
49+
4650
@fixtures.parameterize(
4751
dict(name=None),
4852
dict(name=''),

0 commit comments

Comments
 (0)