-
Notifications
You must be signed in to change notification settings - Fork 7
/
example.py
62 lines (45 loc) · 990 Bytes
/
example.py
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
# match greedy level 0
a = '%s' % '123'
# match greedy level 1
b = ('x' + '%s') % '123'
c = '%s'
# match greedy level 2
d = c % '123'
# false positive greedy level 1
e = '' + str(3 % 2)
# false positive greedy level 2
f = 3 % 2
# match greedy level 0
g = '{val}'.format(val=123)
# match greedy level 1
h = ('x' + '{}').format(123)
i = '{}'
# match greedy level 2
j = i.format(123)
class C:
def format(self): # noqa: A003
return ''
# false positive greedy level 1
k = '' + C().format()
# false positive greedy level 2
m = C().format()
# missing prefix false positive
n = (rf'{m}'
'{'
'}'
'm'
''
'{}'
'{{m}}')
# match missing prefix
o = ('{n}'
'{{m}} {n}'
r'[a-z]{1,3}') # Should not be matched.
# should not be matched on any greedy level < 2
# (bytestrings can't be f-strings)
p = b'%d' % f
# should not be matched for missing prefix
# (bytestrings can't be f-strings)
q = b'{n}'
# no errors below; coverage
''.strip()