From 1bf8a7aec366ede912b9f9c989006cc358cf2cdc Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2023 12:10:08 -0500 Subject: [PATCH 1/3] Add xfail test capturing desired expectation. --- tests/test_main.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 7b8d797f..cec82121 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -43,6 +43,11 @@ def test_package_not_found_mentions_metadata(self): assert "metadata" in str(ctx.exception) + def test_abc_enforced(self): + with self.assertRaises(AssertionError): # xfail + with self.assertRaises(TypeError): + type('DistributionSubclass', (Distribution,), {})() + @fixtures.parameterize( dict(name=None), dict(name=''), From 8a9d1699aa47d71da6fb385b8510bf95fed6e3e2 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2023 12:35:46 -0500 Subject: [PATCH 2/3] Add ABCMeta to Distribution. Fixes #419. --- importlib_metadata/__init__.py | 2 +- tests/test_main.py | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 26a1388c..9a36a8e6 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -346,7 +346,7 @@ def __repr__(self): return f'' -class Distribution: +class Distribution(metaclass=abc.ABCMeta): """A Python distribution package.""" @abc.abstractmethod diff --git a/tests/test_main.py b/tests/test_main.py index cec82121..f0f84983 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -44,9 +44,8 @@ def test_package_not_found_mentions_metadata(self): assert "metadata" in str(ctx.exception) def test_abc_enforced(self): - with self.assertRaises(AssertionError): # xfail - with self.assertRaises(TypeError): - type('DistributionSubclass', (Distribution,), {})() + with self.assertRaises(TypeError): + type('DistributionSubclass', (Distribution,), {})() @fixtures.parameterize( dict(name=None), From 2d52ecd7a581e97012830e7d18932408729d0e9a Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sun, 1 Jan 2023 12:39:00 -0500 Subject: [PATCH 3/3] Update changelog. Ref #419. --- CHANGES.rst | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index a2df91a3..4dd9d5df 100644 --- a/CHANGES.rst +++ b/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 ======