-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathExplicitCallToDel.qhelp
More file actions
33 lines (23 loc) · 992 Bytes
/
ExplicitCallToDel.qhelp
File metadata and controls
33 lines (23 loc) · 992 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<!DOCTYPE qhelp PUBLIC
"-//Semmle//qhelp//EN"
"qhelp.dtd">
<qhelp>
<overview>
<p>The <code>__del__</code> special method is designed to be called by the Python virtual machine when an object is no longer reachable,
but before it is destroyed. Calling a <code>__del__</code> method explicitly may cause an object to enter an unsafe state.</p>
</overview>
<recommendation>
<p>If explicit clean up of an object is required, a <code>close()</code> method should be called or, better still,
wrap the use of the object in a <code>with</code> statement.
</p>
</recommendation>
<example>
<p>In the first example, rather than close the zip file in a conventional manner, the programmer has called <code>__del__</code>.
A safer alternative is shown in the second example.
</p>
<sample src="ExplicitCallToDel.py" />
</example>
<references>
<li>Python Standard Library: <a href="http://docs.python.org/reference/datamodel.html#object.__del__">object.__del__</a></li>
</references>
</qhelp>