Opened 68 minutes ago
#37307 new Bug
Short-circuit evaluation issue
| Reported by: | Twain Byrnes | Owned by: | |
|---|---|---|---|
| Component: | Uncategorized | Version: | 6.1 |
| Severity: | Normal | Keywords: | |
| Cc: | Twain Byrnes | Triage Stage: | Unreviewed |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
Hello,
There are several instances of a potentially problematic behavior in the Python code of the form:
Code highlighting:
def fun_name(par=None): par = par or default_value ...
which may be passed a non-None value of the wrong type, potentially causing errors. I have not found any instances where there it is possible for something to be passed in with the wrong type, but for future-proofing, it may be advisable to change them to the following form:
Code highlighting:
def fun_name(par=None): if par is None: par = default_value ...
I have listed several such instances below:
- In
django/db/models/fields/__init__.py, lines 1101 and 1115 - In
django/db/models/base.py, lines 705 and 706, lines 853 and 867, lines 962 and 974, lines 1333 and 1339
If there is interest, I can also submit a CodeQL query to uncover the remaining items of this form.