From 72b0a6e23baf8e80f1de2cc20a5386da9c276a7e Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 17 Dec 2025 00:31:53 +1300 Subject: [PATCH 1/5] Add deprecation notice for `NamespacePackageEncountered` --- src/grimp/exceptions.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/grimp/exceptions.py b/src/grimp/exceptions.py index 43ec9823..80d31dbd 100644 --- a/src/grimp/exceptions.py +++ b/src/grimp/exceptions.py @@ -1,3 +1,6 @@ +import warnings + + class GrimpException(Exception): """ Base exception for all custom Grimp exceptions to inherit. @@ -17,12 +20,16 @@ class NoSuchContainer(GrimpException): class NamespacePackageEncountered(GrimpException): - """ - Indicates that there was no __init__.py at the top level. - - This indicates a namespace package (see PEP 420), which is not currently supported. More - typically this is just an oversight which can be fixed by adding the __init__.py file. - """ + # https://github.com/python-grimp/grimp/issues/272 + def __init__(self, *args, **kwargs): + warnings.warn( + "NamespacePackageEncountered is deprecated; graphs can now be built from " + "namespace packages starting from Grimp 3.14. This exception will not be " + "raised by Grimp anymore.", + DeprecationWarning, + stacklevel=2, + ) + super().__init__(*args, **kwargs) class NotATopLevelModule(GrimpException): From 11d06bf453a59d05fbfabb6e3d9c82a91e989003 Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 17 Dec 2025 01:13:32 +1300 Subject: [PATCH 2/5] Add test and tweak deprecation approach --- src/grimp/exceptions.py | 17 ++++++++++++++--- tests/unit/test_exceptions.py | 8 ++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/grimp/exceptions.py b/src/grimp/exceptions.py index 80d31dbd..91fbcef2 100644 --- a/src/grimp/exceptions.py +++ b/src/grimp/exceptions.py @@ -1,6 +1,13 @@ import warnings +def __getattr__(name: str): + if name == "NamespacePackageEncountered": + _NamespacePackageEncountered._warn_deprecated() + return _NamespacePackageEncountered + raise AttributeError + + class GrimpException(Exception): """ Base exception for all custom Grimp exceptions to inherit. @@ -19,9 +26,14 @@ class NoSuchContainer(GrimpException): """ -class NamespacePackageEncountered(GrimpException): +class _NamespacePackageEncountered(GrimpException): + """ + Deprecated. + """ + # https://github.com/python-grimp/grimp/issues/272 - def __init__(self, *args, **kwargs): + @staticmethod + def _warn_deprecated(): warnings.warn( "NamespacePackageEncountered is deprecated; graphs can now be built from " "namespace packages starting from Grimp 3.14. This exception will not be " @@ -29,7 +41,6 @@ def __init__(self, *args, **kwargs): DeprecationWarning, stacklevel=2, ) - super().__init__(*args, **kwargs) class NotATopLevelModule(GrimpException): diff --git a/tests/unit/test_exceptions.py b/tests/unit/test_exceptions.py index 073ec929..4a2c7186 100644 --- a/tests/unit/test_exceptions.py +++ b/tests/unit/test_exceptions.py @@ -1,3 +1,5 @@ +import pytest + from grimp import exceptions @@ -54,3 +56,9 @@ def test_different_texts_are_not_equal(self): lineno=3, text="something else wrong", ) + + +class TestNamespacePackageEncountered: + def test_deprecated_access(self): + with pytest.warns(DeprecationWarning): + exceptions.NamespacePackageEncountered From 0e0edd2ac7b2b52929ac8d9b8ed0719114764b0b Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 17 Dec 2025 01:19:26 +1300 Subject: [PATCH 3/5] Add changelog entry for `NamespacePackageEncountered` deprecation --- CHANGELOG.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5f0b68af..f3214e52 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -2,6 +2,11 @@ Changelog ========= +latest +----------------- + +* Deprecate the `NamespacePackageEncountered` exception. + 3.14 (2025-12-10) ----------------- From 264ca18ff0816f0bd7265338293d37691fcadcee Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 17 Dec 2025 01:24:38 +1300 Subject: [PATCH 4/5] Add Nathan McDougall to `AUTHORS.rst` --- AUTHORS.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.rst b/AUTHORS.rst index 64bd714a..2923446a 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -10,3 +10,4 @@ Authors * Shane Smiskol - https://github.com/sshane * Andreas Rammhold - https://github.com/andir * Nicholas Bunn - https://github.com/NicholasBunn +* Nathan McDougall - https://github.com/nathanjmcdougall From 5136d8f819ae2f92ddacfc32043316b83492e3f4 Mon Sep 17 00:00:00 2001 From: Nathan McDougall Date: Wed, 17 Dec 2025 07:23:29 +1300 Subject: [PATCH 5/5] Explicitly mention Grimp 3.16 as the end of the deprecation phase for `NamespacePackageEncountered` --- src/grimp/exceptions.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/grimp/exceptions.py b/src/grimp/exceptions.py index 91fbcef2..15112530 100644 --- a/src/grimp/exceptions.py +++ b/src/grimp/exceptions.py @@ -37,7 +37,7 @@ def _warn_deprecated(): warnings.warn( "NamespacePackageEncountered is deprecated; graphs can now be built from " "namespace packages starting from Grimp 3.14. This exception will not be " - "raised by Grimp anymore.", + "raised by Grimp anymore, and will be removed in Grimp 3.16.", DeprecationWarning, stacklevel=2, )