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 diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 69f6f18b..587b0270 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3,8 +3,9 @@ Changelog ========= latest ----------------- +------ +* Deprecate the `NamespacePackageEncountered` exception. * Improve contribution experience for Windows developers using Just. 3.14 (2025-12-10) diff --git a/src/grimp/exceptions.py b/src/grimp/exceptions.py index 43ec9823..15112530 100644 --- a/src/grimp/exceptions.py +++ b/src/grimp/exceptions.py @@ -1,3 +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. @@ -16,14 +26,22 @@ class NoSuchContainer(GrimpException): """ -class NamespacePackageEncountered(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. + Deprecated. """ + # https://github.com/python-grimp/grimp/issues/272 + @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 " + "raised by Grimp anymore, and will be removed in Grimp 3.16.", + DeprecationWarning, + stacklevel=2, + ) + 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