From c8b342d34fecee40e5d2cb20b527c3f526f87bad Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Mon, 10 Apr 2023 15:34:38 +0200 Subject: [PATCH] Deprecate zope-interface support (#1120) --- changelog.d/1120.deprecation.md | 5 +++++ src/attr/validators.py | 10 ++++++++++ tests/test_validators.py | 13 ++++++++++--- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 changelog.d/1120.deprecation.md diff --git a/changelog.d/1120.deprecation.md b/changelog.d/1120.deprecation.md new file mode 100644 index 000000000..e39584b61 --- /dev/null +++ b/changelog.d/1120.deprecation.md @@ -0,0 +1,5 @@ +The support for *zope-interface* via the `attrs.validators.provides` validator is now deprecated and will be removed in, or after, April 2024. + +The presence of a C-based package in our developement dependencies has caused headaches and we're not under the impression it's used a lot. + +Let us know if you're using it and we might publish it as a separate package. diff --git a/src/attr/validators.py b/src/attr/validators.py index 7dfec61c8..1488554f7 100644 --- a/src/attr/validators.py +++ b/src/attr/validators.py @@ -244,7 +244,17 @@ def provides(interface): :raises TypeError: With a human readable error message, the attribute (of type `attrs.Attribute`), the expected interface, and the value it got. + + .. deprecated:: 23.1.0 """ + import warnings + + warnings.warn( + "attrs's zope-interface support is deprecated and will be removed in, " + "or after, April 2024.", + DeprecationWarning, + stacklevel=2, + ) return _ProvidesValidator(interface) diff --git a/tests/test_validators.py b/tests/test_validators.py index fab040262..d42acf4a6 100644 --- a/tests/test_validators.py +++ b/tests/test_validators.py @@ -349,7 +349,9 @@ class C: def f(self): pass - v = provides(ifoo) + with pytest.deprecated_call(): + v = provides(ifoo) + v(None, simple_attr("x"), C()) def test_fail(self, ifoo): @@ -359,9 +361,12 @@ def test_fail(self, ifoo): value = object() a = simple_attr("x") - v = provides(ifoo) + with pytest.deprecated_call(): + v = provides(ifoo) + with pytest.raises(TypeError) as e: v(None, a, value) + assert ( "'x' must provide {interface!r} which {value!r} doesn't.".format( interface=ifoo, value=value @@ -375,7 +380,9 @@ def test_repr(self, ifoo): """ Returned validator has a useful `__repr__`. """ - v = provides(ifoo) + with pytest.deprecated_call(): + v = provides(ifoo) + assert ( "".format( interface=ifoo