From d9ed5937fe0c2621c53e53e8c7a5ff4bd559de65 Mon Sep 17 00:00:00 2001 From: Hynek Schlawack Date: Sat, 16 Mar 2024 16:55:37 +0100 Subject: [PATCH] Deprecate attr.s's repr_ns (#1263) * Deprecate attr.s's repr_ns It's pointless in Python 3. define et al never had it. * Add news fragment * Fix typo --- changelog.d/1263.deprecation.md | 2 ++ src/attr/_make.py | 14 +++++++++++++- tests/test_make.py | 12 +++++++----- 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 changelog.d/1263.deprecation.md diff --git a/changelog.d/1263.deprecation.md b/changelog.d/1263.deprecation.md new file mode 100644 index 00000000..25939511 --- /dev/null +++ b/changelog.d/1263.deprecation.md @@ -0,0 +1,2 @@ +The *repr_ns* argument to `attr.s` is now deprecated. +It was a workaround for nested classes in Python 2 and is pointless in Python 3. diff --git a/src/attr/_make.py b/src/attr/_make.py index 8fadc64e..710c6179 100644 --- a/src/attr/_make.py +++ b/src/attr/_make.py @@ -1354,7 +1354,8 @@ def attrs( :param str repr_ns: When using nested classes, there was no way in Python 2 to automatically detect that. This argument allows to set a custom - name for a more meaningful ``repr`` output. + name for a more meaningful ``repr`` output. This argument + is pointless in Python 3 and is therefore deprecated. :param bool auto_detect: Instead of setting the *init*, *repr*, *eq*, *order*, and *hash* arguments explicitly, assume they are set to ``True`` **unless any** of the involved methods for one of the @@ -1597,7 +1598,18 @@ def attrs( .. versionadded:: 21.3.0 *match_args* .. versionadded:: 22.2.0 *unsafe_hash* as an alias for *hash* (for :pep:`681` compliance). + .. deprecated:: 24.1.0 *repr_ns* """ + if repr_ns is not None: + import warnings + + warnings.warn( + DeprecationWarning( + "The `repr_ns` argument is deprecated and will be removed in or after April 2025." + ), + stacklevel=2, + ) + eq_, order_ = _determine_attrs_eq_order(cmp, eq, order, None) # unsafe_hash takes precedence due to PEP 681. diff --git a/tests/test_make.py b/tests/test_make.py index 1760964b..e0e0aa96 100644 --- a/tests/test_make.py +++ b/tests/test_make.py @@ -600,11 +600,13 @@ class TestAttributes: Setting repr_ns overrides a potentially guessed namespace. """ - @attr.s(slots=slots_outer) - class C: - @attr.s(repr_ns="C", slots=slots_inner) - class D: - pass + with pytest.deprecated_call(match="The `repr_ns` argument"): + + @attr.s(slots=slots_outer) + class C: + @attr.s(repr_ns="C", slots=slots_inner) + class D: + pass assert "C.D()" == repr(C.D())