Skip to content

Commit 247cb93

Browse files
docs(skill): suggest NamedTuple/dataclass for simple field-bundle classes (#15224)
Per maintainer request on #15081: the new-pull-request skill now reminds the coder to consider `typing.NamedTuple` / `dataclasses.dataclass` for simple classes, and the code-review skill adds an OPTIONAL reviewer hint to suggest them where they simplify the code (never a blocker).
1 parent 2067ce6 commit 247cb93

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

.github/skills/code-review/SKILL.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ suggest the fix — never just "rejected".
3333
- [ ] Descriptive variable and function names (no single letters where a word helps).
3434
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
3535

36+
> **Optional hint:** When a PR hand-writes a simple class that is mostly a
37+
> bundle of fields (a manual `__init__` plus `__repr__`/`__eq__`), it is worth
38+
> **suggesting** `from typing import NamedTuple` or
39+
> `from dataclasses import dataclass` where they would simplify the code. These
40+
> are underutilized tools that our contributors would benefit from using where
41+
> they make sense. Offer it as an optional improvement, not a blocker — do not
42+
> request changes solely because a class was written the longhand way.
43+
3644
#### When a PR fails `ruff check`
3745

3846
Don't just report the failure — try the mechanical fixes and recommend the one

.github/skills/new-pull-request/SKILL.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ Always check at least one Markdown checkbox in the pull request description (the
4141
- [ ] Public functions/classes have **type hints**.
4242
- [ ] Public functions have **doctests that actually pass**.
4343
- [ ] Descriptive variable and function names (no single letters where a word helps).
44+
- [ ] For a simple class that is mostly a bundle of fields, **consider**
45+
`from typing import NamedTuple` or `from dataclasses import dataclass`
46+
instead of a hand-written `__init__`/`__repr__`/`__eq__`. These are
47+
underutilized tools that make simple classes shorter and clearer — use
48+
them where they genuinely simplify the code, not everywhere.
4449
- [ ] Code is formatted and lint-clean (`ruff`, `pre-commit`).
4550
- [ ] `DIRECTORY.md` and `README.md` are **not hand-edited** — the
4651
`algorithms-keeper` bot regenerates them automatically after merge.

0 commit comments

Comments
 (0)