From 47bd5f980f8dd81bbc71fdbe045f19eccd12df81 Mon Sep 17 00:00:00 2001 From: Paul Ganssle Date: Sun, 30 Apr 2023 13:25:45 -0400 Subject: [PATCH] Raise AttributeError in errors module Previously, `hypothesis.errors` would return `None` when any arbitrary attribute was accessed. --- hypothesis-python/RELEASE.rst | 4 ++++ hypothesis-python/src/hypothesis/errors.py | 2 ++ hypothesis-python/tests/cover/test_escalation.py | 5 +++++ 3 files changed, 11 insertions(+) create mode 100644 hypothesis-python/RELEASE.rst diff --git a/hypothesis-python/RELEASE.rst b/hypothesis-python/RELEASE.rst new file mode 100644 index 0000000000..deae6da25f --- /dev/null +++ b/hypothesis-python/RELEASE.rst @@ -0,0 +1,4 @@ +RELEASE_TYPE: patch + +``hypothesis.errors`` will now raise :py:exc:`AttributeError` when attempting +to access an undefined attribute, rather than returning :py:obj:`None`. diff --git a/hypothesis-python/src/hypothesis/errors.py b/hypothesis-python/src/hypothesis/errors.py index 06b77de29d..651e7a45fe 100644 --- a/hypothesis-python/src/hypothesis/errors.py +++ b/hypothesis-python/src/hypothesis/errors.py @@ -132,6 +132,8 @@ def __getattr__(name): ) return BaseExceptionGroup + raise AttributeError(f"Module 'hypothesis.errors' has no attribute {name}") + class DeadlineExceeded(_Trimmable): """Raised when an individual test body has taken too long to run.""" diff --git a/hypothesis-python/tests/cover/test_escalation.py b/hypothesis-python/tests/cover/test_escalation.py index e8ad8623fe..212f462c51 100644 --- a/hypothesis-python/tests/cover/test_escalation.py +++ b/hypothesis-python/tests/cover/test_escalation.py @@ -72,5 +72,10 @@ def test_multiplefailures_deprecation(): assert exc is BaseExceptionGroup +def test_errors_attribute_error(): + with pytest.raises(AttributeError): + errors.ThisIsNotARealAttributeDontCreateSomethingWithThisName + + def test_handles_null_traceback(): esc.get_interesting_origin(Exception())