Skip to content

Python: Modernize 4 queries for missing/multiple calls to init/del methods #19932

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
271f32e
Move missing/multiple calls to init/del queries to folder
joefarebrother Jun 30, 2025
a2fc14a
Update missing call to init
joefarebrother Jun 30, 2025
6f9983a
Add missing call to del
joefarebrother Jun 30, 2025
adcfdf1
Modernize multple calls to init/del
joefarebrother Jul 1, 2025
caddec4
Update alert messages
joefarebrother Jul 1, 2025
71d1179
Fix FPs and typo
joefarebrother Jul 1, 2025
085df26
Move tests and add inline expectation postprocessing
joefarebrother Jul 2, 2025
2faf67d
Update test outputs + fix semantics
joefarebrother Jul 2, 2025
1b4e2fe
Change implenetation of missing calls to use getASuperCallTarget, and…
joefarebrother Jul 3, 2025
16b90a1
Fixes
joefarebrother Jul 3, 2025
b3056fc
Update tests for calls to init + fixes
joefarebrother Jul 3, 2025
73057d3
Add additional test case + update missing del tests
joefarebrother Jul 3, 2025
2e6f35b
Remove case excluding classes with a __new__ method; as it doesn't ma…
joefarebrother Jul 3, 2025
c5b79fa
Update multiple calls queries to include call targets in alert message
joefarebrother Jul 4, 2025
804b9ef
Update tests and add an additional test
joefarebrother Jul 4, 2025
6ca4f32
qhelp: move examples to subfolder
joefarebrother Jul 4, 2025
2e5f470
Update qhelp + alert messages
joefarebrother Jul 4, 2025
d2c68de
Update integration test output
joefarebrother Jul 4, 2025
f1026e4
Add change note
joefarebrother Jul 4, 2025
c47e6e3
Add qldoc
joefarebrother Jul 4, 2025
4b49ac3
Fix changenote formatting
joefarebrother Jul 4, 2025
d163bdf
Fix typos
joefarebrother Jul 4, 2025
e8a65b8
Update integration test outout and fix qhelp
joefarebrother Jul 7, 2025
f5066c7
Remove tostring
joefarebrother Jul 7, 2025
2c93e2c
Inline locationBefore
joefarebrother Jul 14, 2025
7dad89f
Adress review suggestions - cleanups
joefarebrother Jul 14, 2025
d2a8e5d
Fix typo in example
joefarebrother Jul 18, 2025
b33a1c2
Fix doc typo
joefarebrother Jul 21, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add additional test case + update missing del tests
  • Loading branch information
joefarebrother committed Jul 3, 2025
commit 73057d3b6fbe2667afa18f42559e077e7e78bbf8
Original file line number Diff line number Diff line change
@@ -1 +1 @@
| missing_del.py:12:1:12:13 | class X3 | Class X3 may not be cleaned up properly as $@ is not called during deletion. | missing_del.py:9:5:9:22 | Function __del__ | method X2.__del__ |
| missing_del.py:13:1:13:13 | Class X3 | This class does not call $@ during destruction. ($@ may be missing a call to a base class __del__) | missing_del.py:9:5:9:22 | Function __del__ | X2.__del__ | missing_del.py:15:5:15:22 | Function __del__ | X3.__del__ |
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@
class X1(object):

def __del__(self):
pass
print("X1 del")

class X2(X1):

def __del__(self):
print("X2 del")
X1.__del__(self)

class X3(X2):
class X3(X2): # $ Alert - skips X2 del

def __del__(self):
print("X3 del")
X1.__del__(self)

a = X3()
del a
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
| missing_init.py:14:5:14:23 | Function __init__ | This initialization method does not call $@, which may leave $@ partially initialized. | missing_init.py:9:5:9:23 | Function __init__ | B2.__init__ | missing_init.py:13:1:13:13 | Class B3 | B3 |
| missing_init.py:29:5:29:23 | Function __init__ | This initialization method does not call super().__init__, which may cause $@ to be missed during the initialization of $@. | missing_init.py:33:5:33:23 | Function __init__ | UT.__init__ | missing_init.py:42:1:42:21 | Class IUVT | IUVT |
| missing_init.py:70:5:70:23 | Function __init__ | This initialization method does not call $@, which may leave $@ partially initialized. | missing_init.py:64:5:64:23 | Function __init__ | AA.__init__ | missing_init.py:67:1:67:13 | Class AB | AB |
| missing_init.py:124:9:124:27 | Function __init__ | This initialization method does not call $@, which may leave $@ partially initialized. | missing_init.py:117:5:117:23 | Function __init__ | DA.__init__ | missing_init.py:122:5:122:17 | Class DC | DC |
| missing_init.py:134:5:134:23 | Function __init__ | This initialization method does not call $@, which may leave $@ partially initialized. | missing_init.py:117:5:117:23 | Function __init__ | DA.__init__ | missing_init.py:132:1:132:13 | Class DD | DD |
| missing_init.py:13:1:13:13 | Class B3 | This class does not call $@ during initialization. ($@ may be missing a call to a base class __init__) | missing_init.py:9:5:9:23 | Function __init__ | B2.__init__ | missing_init.py:14:5:14:23 | Function __init__ | B3.__init__ |
| missing_init.py:42:1:42:21 | Class IUVT | This class does not call $@ during initialization. (The class lacks an __init__ method to ensure every base class __init__ is called.) | missing_init.py:33:5:33:23 | Function __init__ | UT.__init__ | file://:0:0:0:0 | (none) | |
| missing_init.py:67:1:67:13 | Class AB | This class does not call $@ during initialization. ($@ may be missing a call to a base class __init__) | missing_init.py:64:5:64:23 | Function __init__ | AA.__init__ | missing_init.py:70:5:70:23 | Function __init__ | AB.__init__ |
| missing_init.py:122:5:122:17 | Class DC | This class does not call $@ during initialization. ($@ may be missing a call to a base class __init__) | missing_init.py:117:5:117:23 | Function __init__ | DA.__init__ | missing_init.py:124:9:124:27 | Function __init__ | DB.DC.__init__ |
| missing_init.py:132:1:132:13 | Class DD | This class does not call $@ during initialization. ($@ may be missing a call to a base class __init__) | missing_init.py:117:5:117:23 | Function __init__ | DA.__init__ | missing_init.py:134:5:134:23 | Function __init__ | DD.__init__ |
| missing_init.py:200:1:200:17 | Class H3 | This class does not call $@ during initialization. ($@ may be missing a call to super().__init__) | missing_init.py:197:5:197:23 | Function __init__ | H2.__init__ | missing_init.py:193:5:193:23 | Function __init__ | H1.__init__ |
16 changes: 16 additions & 0 deletions python/ql/test/query-tests/Classes/missing-init/missing_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,19 @@ def __init__(self):
for cls in self.__class__.__bases__:
cls.__init__(self) # We dont track which classes this could refer to, but assume it calls all required init methods and don't alert.

G3()

class H1:
def __init__(self):
print("H1 init")

class H2:
def __init__(self):
print("H2 init")

class H3(H1, H2): # $ Alert # The alert should also mention that H1.__init__ may be missing a call to super().__init__
def __init__(self):
print("H3 init")
super().__init__()

H3()
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy