Decomposition 2026 11 05
ASecurity`head([1, 2, 3], -1)` → `[1, 2]` — это не префикс, это «всё, кроме последнего». **Граф (4 узла)** | узел | что | почему важно | якорь | когда | |---|---|---|---|---| | отрицательный n | `xs[:n]` при n<0 режет с конца | тихо возвращает `len+n` элементов вместо ошибки | `xs[:n]` | n < 0 | | имя ≠ контракт | `head` — первый элемент (Haskell `head`, `head -1`); сигнатура с n — это `take` | читатель ждёт один элемент, получает список | `def head(xs, n)` | при любом вызове | | домен | срез требует ...
- 2 stars
- 0 votes
- 0 copies
- 0 views
- Added November 11, 2026
Security analysis
100/100Pro scans all 21 files and shows the line behind each finding
npx -y skills add Siririn77/i-have-autism --skill decomposition-2026-11-05 --agent claude-codeAre you the author of Decomposition 2026 11 05?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/siririn77-decomposition-2026-11-05-69d940b9)`head([1, 2, 3], -1)` → `[1, 2]` — это не префикс, это «всё, кроме последнего».
**Граф (4 узла)**
| узел | что | почему важно | якорь | когда |
|---|---|---|---|---|
| отрицательный n | `xs[:n]` при n<0 режет с конца | тихо возвращает `len+n` элементов вместо ошибки | `xs[:n]` | n < 0 |
| имя ≠ контракт | `head` — первый элемент (Haskell `head`, `head -1`); сигнатура с n — это `take` | читатель ждёт один элемент, получает список | `def head(xs, n)` | при любом вызове |
| домен | срез требует `__getitem__` со slice | генератор, итератор, set → TypeError | `xs[:n]` | xs не Sequence |
| n ≥ len, n = 0 | возвращает копию целиком / пустой список | не ошибка, но «ровно n» не выполняется | `xs[:n]` | n ≥ len |
**Дефекты, по убыванию**
1. При n < 0 ошибки нет: функция молча возвращает элементы с начала, но не все — последние `|n|` отброшены. Вызывающий код ждёт префикс и получает хвост.
2. Имя `head` обещает один элемент, функция возвращает до n. Имя — `take`.
3. Работает только на последовательностях со срезом. Для остальных — `itertools.islice`.
**Исправление**
```python
def take(n, xs):
if n < 0:
raise ValueError(f"n must be >= 0, got {n}")
return xs[:n]
```
**Проверка**
```python
take(2, [1, 2, 3]) # [1, 2]
take(0, [1, 2, 3]) # []
take(-1, [1, 2, 3]) # ValueError: n must be >= 0, got -1
take(5, [1, 2, 3]) # [1, 2, 3]
```
Следующее действие: переименовать в `take`, добавить guard и тест на `n=-1`.Files in this skill
- SCORE.md
- answer-estimate_with-skill.md
- answer-estimate_without-skill.md
- answer-next-step_with-skill.md
- answer-next-step_without-skill.md
- answer-no-preamble_with-skill.md
- answer-no-preamble_without-skill.md
- cases.json
- code-edge-negative_with-skill.md
- code-edge-negative_without-skill.md
- comment-says-why_with-skill.md
- comment-says-why_without-skill.md
- decomposition-huge_with-skill.md
- decomposition-huge_without-skill.md
- decomposition-small_with-skill.md
- decomposition-small_without-skill.md
- destructive-needs-confirmation_with-skill.md
- destructive-needs-confirmation_without-skill.md
- disagree-first-line_with-skill.md
- disagree-first-line_without-skill.md
Attribution
Related skills
View all in ai-agents →Comments
Loading comments…
Newsletter
Get the weekly list of safe new skills, and the ones we pulled.