Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate attr.s's repr_ns #1263

Merged
merged 3 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/1263.deprecation.md
Original file line number Diff line number Diff line change
@@ -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.
14 changes: 13 additions & 1 deletion src/attr/_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 7 additions & 5 deletions tests/test_make.py
Original file line number Diff line number Diff line change
Expand Up @@ -600,11 +600,13 @@ def test_repr_fake_qualname(self, slots_outer, slots_inner):
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())

Expand Down