From 26f505614ecaa5abd420d987a820f660fb861ea3 Mon Sep 17 00:00:00 2001 From: Finite State Machine Date: Mon, 23 Feb 2026 12:22:18 -0500 Subject: [PATCH 1/3] Fix `@auto` to be safe with `tuple`-valued attributes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Problem being fixed: When `@auto` is representing an attribute (`__init__()` arg) which is emitted as positional (rather than with the attribute name), the implementation yields the value directly. If that value is a `tuple`, it will be misinterpreted as a `(name, value, ...)` group, causing `TypeError`s later when rendering. --- rich/repr.py | 4 ++-- tests/test_repr.py | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/rich/repr.py b/rich/repr.py index 95331006ee..c6e7761b4c 100644 --- a/rich/repr.py +++ b/rich/repr.py @@ -71,13 +71,13 @@ def auto_rich_repr(self: Type[T]) -> Result: signature = inspect.signature(self.__init__) for name, param in signature.parameters.items(): if param.kind == param.POSITIONAL_ONLY: - yield getattr(self, name) + yield None, getattr(self, name) elif param.kind in ( param.POSITIONAL_OR_KEYWORD, param.KEYWORD_ONLY, ): if param.default is param.empty: - yield getattr(self, param.name) + yield None, getattr(self, param.name) else: yield param.name, getattr(self, param.name), param.default except Exception as error: diff --git a/tests/test_repr.py b/tests/test_repr.py index 94fd6da1f6..4147101159 100644 --- a/tests/test_repr.py +++ b/tests/test_repr.py @@ -124,6 +124,9 @@ def test_rich_repr_auto() -> None: == f"Bird('penguin', ['fish'], another={repr(stupid_class)}, extinct={repr(not_stupid)})" ) +def test_rich_repr_auto_with_tuples() -> None: + assert repr(Egg(('hello', 'world'), egg=2)) == "Egg(('hello', 'world'), egg=2)" + def test_rich_repr_auto_angular() -> None: assert repr(AngularEgg("hello", egg=2)) == "" From 094dc91e2799474c4517e658b7e75357c6bb8670 Mon Sep 17 00:00:00 2001 From: Finite State Machine Date: Mon, 23 Feb 2026 13:44:57 -0500 Subject: [PATCH 2/3] Amend changelog.md, contributors.md --- CHANGELOG.md | 6 ++++++ CONTRIBUTORS.md | 1 + 2 files changed, 7 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bdd4f15974..b01b11ac60 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## Unreleased + +### Fixed + +- Fixed `@auto` to be safe with `tuple`-valued positionals https://github.com/Textualize/rich/pull/4014 + ## [14.3.3] - 2026-02-19 ### Fixed diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 4d77a0e3ed..136bb13c79 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -100,3 +100,4 @@ The following people have contributed to the development of Rich: - [Brandon Capener](https://github.com/bcapener) - [Alex Zheng](https://github.com/alexzheng111) - [Sebastian Speitel](https://github.com/SebastianSpeitel) +- [David S.](https://github.com/finite-state-machine) From a533fa3224d40e40d72ec51025b02be3e974566f Mon Sep 17 00:00:00 2001 From: Finite State Machine Date: Mon, 23 Feb 2026 13:52:18 -0500 Subject: [PATCH 3/3] Reference the issue rather than the pull request in `CHANGELOG.md` --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b01b11ac60..bbfe8c5fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Fixed -- Fixed `@auto` to be safe with `tuple`-valued positionals https://github.com/Textualize/rich/pull/4014 +- Fixed `@auto` to be safe with `tuple`-valued positionals https://github.com/Textualize/rich/issues/4016 ## [14.3.3] - 2026-02-19