Skip to content

Remove deprecation warning for Batch.__len__ again.#125

Merged
mauritsvanrees merged 2 commits into
mainfrom
maurits-undeprecate-batch-len
Jun 8, 2026
Merged

Remove deprecation warning for Batch.__len__ again.#125
mauritsvanrees merged 2 commits into
mainfrom
maurits-undeprecate-batch-len

Conversation

@mauritsvanrees

Copy link
Copy Markdown
Member

Calling this method is simly unavoidable.
When a page template does a tal:repeat over a batch, Products.PageTemplates calls list(batch) and len(batch), both of which invoke calling __len__. You can try this out with bin/zopepy:

$ bin/zopepy
>>> from plone.base.batch import Batch
>>> len(Batch(range(10), 3))
<console>:1: DeprecationWarning: Use length attribute instead of __len__
3
>>> list(Batch(range(10), 3))
<console>:1: DeprecationWarning: Use length attribute instead of __len__
[0, 1, 2]

The deprecation warning was removed in Plone 5.2.3, see plone/Products.CMFPlone#3176 But during the move of the Batch class to plone.base in Plone 6.0 it was added again. Compare:

@mister-roboto

Copy link
Copy Markdown

@mauritsvanrees thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

Calling this method is simly unavoidable.
When a page template does a `tal:repeat` over a batch, `Products.PageTemplates` calls `list(batch)` and `len(batch)`, both of which invoke calling `__len__`.
You can try this out with `bin/zopepy`:

```
$ bin/zopepy
>>> from plone.base.batch import Batch
>>> len(Batch(range(10), 3))
<console>:1: DeprecationWarning: Use length attribute instead of __len__
3
>>> list(Batch(range(10), 3))
<console>:1: DeprecationWarning: Use length attribute instead of __len__
[0, 1, 2]
```

The deprecation warning was removed in Plone 5.2.3, see plone/Products.CMFPlone#3176
But during the move of the `Batch` class to `plone.base` in Plone 6.0 it was added again.
Compare:

* plone/Products.CMFPlone@2cc2515#diff-fa1e7e5e81879e8c4f4485cf8d8204eba6f2677cb9f4e29de4776b0c1f0d4d93L21
* 6e26a37#diff-316da888fe8d39c68d5e0aee055b3bbfa95d522b4b09fe56b7edb1289bd72f9fR28
@mauritsvanrees mauritsvanrees force-pushed the maurits-undeprecate-batch-len branch from 15c63c0 to 0599597 Compare June 5, 2026 21:08
@mauritsvanrees

Copy link
Copy Markdown
Member Author

@jenkins-plone-org please run jobs

@mauritsvanrees mauritsvanrees merged commit 2f382ee into main Jun 8, 2026
16 checks passed
@mauritsvanrees mauritsvanrees deleted the maurits-undeprecate-batch-len branch June 8, 2026 09:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants