---
title: "funcy: partition and chunks on iterators in Python | VulCode"
description: "A fix to funcy in Python: partition and chunks with a step larger than the part size now yield the same, correct parts for an iterator as for a list."
url: "https://vulcode.com/en/opensource/contributions/funcy"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/contributions)

Suor/funcy

# funcy

A collection of practical functional tools for Python, including helpers for sequences, collections and iterators.

[See the repository](https://github.com/Suor/funcy) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: Python
- **GitHub stars**: 3,507
- **Merged changes**: 1

## What we changed

partition and chunks with a step larger than the part size now give the same parts for an iterator as for a list: the right length and the right items.

### What this work shows

- Python iterators and itertools.islice

- Sliding window edge cases

- Tests comparing two implementations

What was broken

### An iterator gave different parts than a list

partition(2, 3, ...) on a list gave [[0, 1], [3, 4], [6, 7]], but on an iterator over the same data it gave [[0, 1], [2, 3, 4], [5, 6, 7], [8, 9]]. In _cut_iter the sliding window only worked when the step was not larger than the part size, and a larger step pulled in too many items.

How we fixed it

### Skipping the gap between parts

For a step smaller than the part size the sliding window stays, and otherwise _cut_iter discards the step - n items in the gap and takes n fresh ones. Tests compare partition and chunks on an iterator and on a list.

[#177](https://github.com/Suor/funcy/pull/177)

## Merged change

1 10 September 2026

- [01 #177Merged 10 September 2026 fix: _cut_iter yields wrong-length/wrong-content parts when step > n](https://github.com/Suor/funcy/pull/177)

## What it taught us

When a function has separate paths for lists and for iterators, we compare both paths on the same data. That is how edge case bugs surface that no test had touched before.

[More about this technology: Python](https://vulcode.com/en/technologies/python)

## Other projects we write code for

- [**more-itertools** Python · 4,106 stars A Python library with more routines for operating on iterables, beyond the itertools module.](https://vulcode.com/en/opensource/contributions/more-itertools)

- [**python-benedict** Python · 1,606 stars A Python dict subclass with key path access and built-in reading and writing of many formats, such as JSON, YAML, TOML and CSV.](https://vulcode.com/en/opensource/contributions/python-benedict)

- [**pydash** Python · 1,449 stars A Python utility library modelled on Lo-Dash from JavaScript. It offers ready-made operations on lists, dicts and strings in a functional style.](https://vulcode.com/en/opensource/contributions/pydash)

- [**pydantic-extra-types** Python · 345 stars Extra types for data validation in Pydantic, the popular Python library: MAC addresses, time zones, semantic versions, ULIDs and many more.](https://vulcode.com/en/opensource/contributions/pydantic-extra-types)

- [**pytimeparse** Python · 296 stars A small Python module that turns time expressions such as 1h30m or 1:24 into a number of seconds.](https://vulcode.com/en/opensource/contributions/pytimeparse)

- [**Node.js** JavaScript · 123,955 stars The JavaScript runtime built on V8 that runs servers, command line tools and front-end build pipelines. It ships a built-in node:sqlite module for working with SQLite databases.](https://vulcode.com/en/opensource/contributions/nodejs)

## Describe your project.

A free quote comes back within an hour during working hours.

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
