Decomposition 2026 11 05
ASecurityСама по себе она не «сломана» для последовательностей вроде `list`, `tuple`, `str` и неотрицательного целого `n`: `xs[:n]` вернёт первые `n` элементов. Но есть несколько проблем/подводных камней: 1. **Отрицательное `n` работает не так, как ожидается от `head`/`take`.** В Python срез `xs[:n]` при `n < 0` означает «всё, кроме последних `|n|` элементов»: ```python head([1, 2, 3], -1) # [1, 2], а не ошибка и не [] ``` Обычно для «взять первые n» отрицательное `n` должно давать `ValueError` или п...
- 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-f04d2b80)Сама по себе она не «сломана» для последовательностей вроде `list`, `tuple`, `str` и неотрицательного целого `n`: `xs[:n]` вернёт первые `n` элементов.
Но есть несколько проблем/подводных камней:
1. **Отрицательное `n` работает не так, как ожидается от `head`/`take`.**
В Python срез `xs[:n]` при `n < 0` означает «всё, кроме последних `|n|` элементов»:
```python
head([1, 2, 3], -1) # [1, 2], а не ошибка и не []
```
Обычно для «взять первые n» отрицательное `n` должно давать `ValueError` или пустой результат.
2. **Имя `head` обычно означает «первый элемент», а не «первые n элементов».**
В Haskell/многих библиотеках `head(xs)` — это `xs[0]`. Для «первые n» лучше имя `take`.
3. **Функция работает только с объектами, поддерживающими срезы.**
Для генератора/итератора будет ошибка:
```python
head((x for x in range(10)), 3) # TypeError
```
Для произвольного итерируемого нужно что-то вроде `itertools.islice`.
4. **Нет валидации `n`.**
Например, `n=None` или `n=1.5` приведут к `TypeError`; это может быть нормально, но если функция публичная, лучше явно проверять контракт.
Более аккуратный вариант для последовательностей:
```python
def take(xs, n):
if not isinstance(n, int):
raise TypeError("n must be an integer")
if n < 0:
raise ValueError("n must be non-negative")
return xs[:n]
```
Если же нужен именно `head` как «первый элемент»:
```python
def head(xs):
if not xs:
raise ValueError("empty sequence")
return xs[0]
```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.