Skip to content

Commit

Permalink
Merge pull request #3187 from plone/maurits/un-deprecate-len-batch-is…
Browse files Browse the repository at this point in the history
…sue-3176

No longer consider calling len(batch) as deprecated.
  • Loading branch information
jensens authored Sep 28, 2020
2 parents 90fa276 + 52a3267 commit b03619d
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 b03619d

Please sign in to comment.