Skip to content

Commit

Permalink
No longer consider calling len(batch) as deprecated.
Browse files Browse the repository at this point in the history
The deprecation warning is unvoidable with current `Products.PageTemplates` code.
Fixes #3176

(cherry picked from commit 52a3267)
  • Loading branch information
mauritsvanrees authored and jensens committed Sep 28, 2020
1 parent dc0a7b7 commit 6eec885
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Products/CMFPlone/PloneBatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,17 @@ def __init__(self, sequence, size, start=0, end=0, orphan=0,
self.b_start_str = b_start_str

def __len__(self):
# Note: Using len() was deprecated for several years.
# It was recommended to explicitly either use the `length` attribute
# for the size of the current page, which is what we return now,
# or use the `sequence_length` attribute for the size of the
# entire sequence.
# But the deprecation was reverted for Plone 5.2.3,
# because core code in Products.PageTemplates called `len`
# on batches, making the deprecation warning unavoidable
# and thus unnecessary.
# See https://github.com/plone/Products.CMFPlone/issues/3176
return self.length
__len__ = deprecated(__len__,
('Using len() is deprecated. Use the `length` attribute for the '
'size of the current page, which is what we return now. '
'Use the `sequence_length` attribute for the size of the '
'entire sequence. '))

def __bool__(self):
# Without __bool__ a bool(self) would call len(self), which
Expand Down
4 changes: 4 additions & 0 deletions news/3176.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
No longer consider calling ``len(batch)`` as deprecated.
The deprecation warning is unvoidable with current ``Products.PageTemplates`` code.
Fixes `issue 3176 <https://github.com/plone/Products.CMFPlone/issues/3176>`_.
maurits

0 comments on commit 6eec885

Please sign in to comment.