Skip to content

Commit a307c58

Browse files
s19110myteron
andauthored
Update docs/Secure-Coding-Guide-for-Python/CWE-697/CWE-595/README.md
Co-authored-by: myteron <[email protected]> Signed-off-by: Hubert Daniszewski <[email protected]>
1 parent 551425b commit a307c58

File tree

1 file changed

+7
-1
lines changed
  • docs/Secure-Coding-Guide-for-Python/CWE-697/CWE-595

1 file changed

+7
-1
lines changed

docs/Secure-Coding-Guide-for-Python/CWE-697/CWE-595/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,13 @@ The first set of print statements illustrates string interning. While `a` and `b
5757

5858
## Non-Compliant Code Example
5959

60-
The non-compliant code shows how the default comparison operator compares object references rather than the object values. Furthermore, it displays how this causes issues when comparing lists of objects, although it applies to other types of collections as well. Then, it shows how the `in` operator also depends on the behavior of the `__eq__` method and, therefore, also returns a non-desirable result. Finally, it performs the comparison with the `is` operator, which checks as to whether the references point to the same object regardless of the stored value.
60+
The `noncompliant01.py` code demonstrates potentially unexpected outcomes when using different comparisons.
61+
62+
* The `==` operator using `__eq__`, checks value equality for most build-in types, checks for reference equality if the `__eq__` is missing in a custom class. So 12 == 12 is True and Integer(12) == Integer(12) is False.
63+
* The `==` comparing lists of objects, that also applies to other types of collections.
64+
* The `in` operator also depends on the behavior of the `__eq__` method
65+
* The `is` operator that checks the references point to the same object regardless of the stored value.
66+
6167

6268
_[noncompliant01.py:](noncompliant01.py)_
6369

0 commit comments

Comments
 (0)