-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathtest.py
More file actions
66 lines (51 loc) · 1.35 KB
/
test.py
File metadata and controls
66 lines (51 loc) · 1.35 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#Non-callable called
class NonCallable(object):
pass
class MaybeCallable(Unknown, object):
pass
class IsCallable(object):
def __call__(self):
pass
def call_non_callable(arg):
non = NonCallable()
non(arg)
()()
[]()
dont_know = MaybeCallable()
dont_know() # Not a violation
ok = IsCallable()
ok()
if hasattr(non, "__call__"):
non(arg) # OK due to guard
if hasattr(non, "__init__"):
non(arg) # Not OK due to wrong guard
import six
#ODASA-4812
def call_six_guarded(arg=None):
# If it's a callable, call it
if six.callable(arg):
arg = arg()
#ODASA-6261
def experimental_jit_scope(compile_ops=True, separate_compiled_gradients=False):
if callable(compile_ops):
def xla_compile(node_def):
return attr_value_pb2.AttrValue(b=compile_ops(node_def))
def foo():
#This is so common, we have a different query for it
raise NotImplemented()
def bar():
return NotImplemented()
# FP due to decorator
# https://github.com/Semmle/ql/issues/3113
def some_decorator(func):
print("this could be tricky for our analysis")
return func
class Foo(object):
def __init__(self, arg):
self.arg = arg
@some_decorator
@classmethod
def new_instance(cls, new_arg):
return cls(new_arg) # TODO: FP
f1 = Foo(1)
f2 = f1.new_instance(2)