mirror of
https://github.com/github/codeql.git
synced 2026-05-05 05:35:13 +02:00
Merge pull request #2540 from RasmusWL/python-modernise-variables-queries
Python: modernise variables queries
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
| test.py:3:5:3:20 | Function MyStr.upper | overriding | not overridden |
|
||||
| test.py:11:1:11:26 | Function outside_func | not overriding | overridden |
|
||||
| test.py:16:11:16:29 | Function Base.lambda | not overriding | overridden |
|
||||
| test.py:18:24:18:36 | Function Base.lambda | not overriding | not overridden |
|
||||
| test.py:22:5:22:21 | Function Base.normal | not overriding | overridden |
|
||||
| test.py:33:5:33:21 | Function Bar.foo | overriding | overridden |
|
||||
| test.py:36:5:36:24 | Function Bar.tricky | overriding | not overridden |
|
||||
| test.py:41:5:41:21 | Function SpecialBar.foo | overriding | not overridden |
|
||||
| test.py:44:5:44:18 | Function SpecialBar.baz | overriding | not overridden |
|
||||
@@ -0,0 +1,7 @@
|
||||
import python
|
||||
|
||||
from PythonFunctionValue f, string overriding, string overridden
|
||||
where
|
||||
(if f.isOverridingMethod() then overriding = "overriding" else overriding = "not overriding") and
|
||||
(if f.isOverriddenMethod() then overridden = "overridden" else overridden = "not overridden")
|
||||
select f, overriding, overridden
|
||||
54
python/ql/test/library-tests/overrides/test.py
Normal file
54
python/ql/test/library-tests/overrides/test.py
Normal file
@@ -0,0 +1,54 @@
|
||||
class MyStr(str):
|
||||
|
||||
def upper(self):
|
||||
return self.lower()
|
||||
|
||||
|
||||
s = MyStr('asdf')
|
||||
print(s.upper(), len(s))
|
||||
|
||||
|
||||
def outside_func(self, x):
|
||||
print(x)
|
||||
|
||||
class Base(object):
|
||||
|
||||
foo = lambda self, x: x+1
|
||||
|
||||
bar = staticmethod(lambda x: x+1)
|
||||
|
||||
baz = 123
|
||||
|
||||
def normal(self):
|
||||
pass
|
||||
|
||||
tricky = outside_func
|
||||
|
||||
class Foo(Base):
|
||||
|
||||
normal = False
|
||||
|
||||
class Bar(Base):
|
||||
|
||||
def foo(self, y):
|
||||
return y * 100
|
||||
|
||||
def tricky(self, x):
|
||||
print('tricky!', x)
|
||||
|
||||
class SpecialBar(Bar):
|
||||
|
||||
def foo(self, z):
|
||||
return z / 123
|
||||
|
||||
def baz(self):
|
||||
print('baz')
|
||||
|
||||
|
||||
b = Base()
|
||||
print(b.foo(1))
|
||||
print(b.bar(10))
|
||||
|
||||
sb = SpecialBar()
|
||||
print(sb.foo(1))
|
||||
sb.baz()
|
||||
@@ -10,7 +10,7 @@ def OK1(seq):
|
||||
for _ in seq:
|
||||
do_something()
|
||||
print("Hi")
|
||||
|
||||
|
||||
#OK counting
|
||||
def OK2(seq):
|
||||
i = 3
|
||||
@@ -29,7 +29,7 @@ def OK4(n):
|
||||
r = range(n)
|
||||
for i in r:
|
||||
print("x")
|
||||
|
||||
|
||||
#OK named as unused
|
||||
def OK5(seq):
|
||||
for unused_x in seq:
|
||||
@@ -77,7 +77,7 @@ def fail4(coll, sequence):
|
||||
x = coll.pop()
|
||||
for s in sequence:
|
||||
do_something(x+1)
|
||||
|
||||
|
||||
#OK See ODASA-4153 and ODASA-4533
|
||||
def fail5(t):
|
||||
x, y = t
|
||||
@@ -106,3 +106,12 @@ def cleanup(sessions):
|
||||
for sess in sessions:
|
||||
# Original code had some comment about deleting sessions
|
||||
del sess
|
||||
|
||||
# For SuspiciousUnusedLoopIterationVariable.ql
|
||||
# ok
|
||||
for x in list(range(100)):
|
||||
print('hi')
|
||||
|
||||
# ok
|
||||
for y in list(list(range(100))):
|
||||
print('hi')
|
||||
|
||||
Reference in New Issue
Block a user