From 088b6830d307c8912838f62d51fe56b04cc3fd15 Mon Sep 17 00:00:00 2001 From: Matthew Einhorn Date: Thu, 24 Jul 2014 14:11:28 -0400 Subject: [PATCH] Warn about list/dict property copying. --- kivy/properties.pyx | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/kivy/properties.pyx b/kivy/properties.pyx index 70aff32fd..617959b12 100644 --- a/kivy/properties.pyx +++ b/kivy/properties.pyx @@ -610,6 +610,22 @@ cdef class ListProperty(Property): `default`: list, defaults to [] Specifies the default value of the property. + .. warning:: + + When assigning a list to a :class:`ListProperty`, the list stored in + the property is a copy of the list and not the original list. This can + be demonstrated with the following example:: + + >>> class MyWidget(Widget): + >>> my_list = ListProperty([]) + + >>> widget = MyWidget() + >>> my_list = widget.my_list = [1, 5, 7] + >>> print my_list is widget.my_list + False + >>> my_list.append(10) + >>> print(my_list, widget.my_list) + [1, 5, 7, 10], [1, 5, 7] ''' def __init__(self, defaultvalue=None, **kw): defaultvalue = defaultvalue or [] @@ -713,6 +729,12 @@ cdef class DictProperty(Property): .. versionchanged:: 1.8.1 `rebind` has been introduced. + + .. warning:: + + Similar to :class:`ListProperty`, when assigning a dict to a + :class:`DictProperty`, the dict stored in the property is a copy of the + dict and not the original dict. See :class:`ListProperty` for details. ''' def __init__(self, defaultvalue=None, rebind=False, **kw): defaultvalue = defaultvalue or {}