[issue33703] Object deletion and re-creation points to same attribute if attribute is a dictionary.

Nitin Bhojwani report at bugs.python.org
Thu May 31 00:18:48 EDT 2018


New submission from Nitin Bhojwani <nitinbhojwani1993 at gmail.com>:

I observed a strange behaviour while working on a module.
This bug is present in multiple python version so seems it is related to core-interpreter.

Behaviour can be reproduced by:
1. Create an object and in __init__ of class, we define a dictionary attribute to that object.
2. After that we change that attribute, like assign any key-value(s) to that attribute.
3. Delete the object.
4. recreate the object.
5. If you check, this new object's same attribute(dictionary) is same old attribute which was pointed by the older object.

This is a behavioural bug, as once delete is performed on an object the whole object and it's (attributes') references must be removed.

I can demonstrate this using a test from unittest, in which I put instance creation in setUp phase, instance deletion in tearDown phase and run same test multiple times. The result is different each time.

The zip file contains ngraph.py which defines a class and test_util.py which runs test against it.
Unzip and execute as:

python test_util.py #2.7.10
python3 test_util.py #3.6.3

----------
components: Interpreter Core
files: test-bug.zip
messages: 318241
nosy: Nitin Bhojwani
priority: normal
severity: normal
status: open
title: Object deletion and re-creation points to same attribute if attribute is a dictionary.
type: behavior
versions: Python 3.6
Added file: https://bugs.python.org/file47627/test-bug.zip

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue33703>
_______________________________________


More information about the Python-bugs-list mailing list