Skip to content

Commit

Permalink
Merge f43241d into a449b8c
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Oct 7, 2020
2 parents a449b8c + f43241d commit 3548aee
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGES.rst
Expand Up @@ -10,6 +10,10 @@ https://zope.readthedocs.io/en/2.13/CHANGES.html
4.5.2 (unreleased)
------------------

- Provide a more senseful ``OFS.SimpleItem.Item_w__name__.id``
to avoid bugs by use of deprecated direct ``id`` access
(as e.g. (`#903 <https://github.com/zopefoundation/Zope/issues/903>`_).

- Update dependencies to the latest releases that still support Python 2.

- Update to ``zope.interface > 5.1.0`` to fix a memory leak.
Expand Down
4 changes: 4 additions & 0 deletions src/OFS/SimpleItem.py
Expand Up @@ -446,6 +446,10 @@ def getId(self):
"""
return self.__name__

# Alias (deprecated) `id` to `getId()` (but avoid recursion)
id = ComputedAttribute(
lambda self: self.getId() if "__name__" in self.__dict__ else "")

def title_or_id(self):
"""Return the title if it is not blank and the id otherwise.
"""
Expand Down
11 changes: 11 additions & 0 deletions src/OFS/tests/testSimpleItem.py
Expand Up @@ -79,6 +79,17 @@ def test_interfaces(self):

verifyClass(IItemWithName, Item_w__name__)

def test_id(self):
from OFS.SimpleItem import Item_w__name__
itm = Item_w__name__()
# fall back to inherited `id`
self.assertEqual(itm.id, "")
itm.id = "id"
self.assertEqual(itm.id, "id")
del itm.id
itm._setId("name")
self.assertEqual(itm.id, "name")


class TestSimpleItem(unittest.TestCase):

Expand Down

0 comments on commit 3548aee

Please sign in to comment.