Skip to content

Commit ed19417

Browse files
committed
PEP 8: test for membership should be 'not in', https://www.python.org/dev/peps/pep-0008/#other-recommendations
1 parent 8d5e14c commit ed19417

1 file changed

Lines changed: 38 additions & 38 deletions

File tree

rivescript/rivescript.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def _parse(self, fname, code):
269269
elif line[0] == '#':
270270
self._warn("Using the # symbol for comments is deprecated", fname, lineno)
271271
elif line[:2] == '/*': # Start of a multi-line comment.
272-
if not '*/' in line: # Cancel if the end is here too.
272+
if '*/' not in line: # Cancel if the end is here too.
273273
comment = True
274274
continue
275275
elif '*/' in line:
@@ -522,11 +522,11 @@ def _parse(self, fname, code):
522522
elif mode != '':
523523
# This topic is either inherited or included.
524524
if mode == 'includes':
525-
if not name in self._includes:
525+
if name not in self._includes:
526526
self._includes[name] = {}
527527
self._includes[name][field] = 1
528528
else:
529-
if not name in self._lineage:
529+
if name not in self._lineage:
530530
self._lineage[name] = {}
531531
self._lineage[name][field] = 1
532532
elif type == 'object':
@@ -767,7 +767,7 @@ def deparse(self):
767767
dest = result["begin"]["triggers"]
768768
else:
769769
# Normal topic.
770-
if not topic in result["topic"]:
770+
if topic not in result["topic"]:
771771
result["topic"][topic] = {}
772772
dest = result["topic"][topic]
773773

@@ -784,7 +784,7 @@ def deparse(self):
784784
dest = result["begin"]["that"]
785785
else:
786786
# Normal topic.
787-
if not topic in result["that"]:
787+
if topic not in result["that"]:
788788
result["that"][topic] = {}
789789
dest = result["that"][topic]
790790

@@ -872,7 +872,7 @@ def write(self, fh, deparsed=None):
872872
topics.extend(sorted(deparsed["topic"].keys()))
873873
done_random = False
874874
for topic in topics:
875-
if not topic in deparsed["topic"]: continue
875+
if topic not in deparsed["topic"]: continue
876876
if topic == "random" and done_random: continue
877877
if topic == "random": done_random = True
878878

@@ -986,29 +986,29 @@ def _write_wrapped(self, line, sep=" ", indent="", width=78):
986986
def _initTT(self, toplevel, topic, trigger, what=''):
987987
"""Initialize a Topic Tree data structure."""
988988
if toplevel == 'topics':
989-
if not topic in self._topics:
989+
if topic not in self._topics:
990990
self._topics[topic] = {}
991-
if not trigger in self._topics[topic]:
991+
if trigger not in self._topics[topic]:
992992
self._topics[topic][trigger] = {}
993993
self._topics[topic][trigger]['reply'] = {}
994994
self._topics[topic][trigger]['condition'] = {}
995995
self._topics[topic][trigger]['redirect'] = None
996996
elif toplevel == 'thats':
997-
if not topic in self._thats:
997+
if topic not in self._thats:
998998
self._thats[topic] = {}
999-
if not trigger in self._thats[topic]:
999+
if trigger not in self._thats[topic]:
10001000
self._thats[topic][trigger] = {}
1001-
if not what in self._thats[topic][trigger]:
1001+
if what not in self._thats[topic][trigger]:
10021002
self._thats[topic][trigger][what] = {}
10031003
self._thats[topic][trigger][what]['reply'] = {}
10041004
self._thats[topic][trigger][what]['condition'] = {}
10051005
self._thats[topic][trigger][what]['redirect'] = {}
10061006
elif toplevel == 'syntax':
1007-
if not what in self._syntax:
1007+
if what not in self._syntax:
10081008
self._syntax[what] = {}
1009-
if not topic in self._syntax[what]:
1009+
if topic not in self._syntax[what]:
10101010
self._syntax[what][topic] = {}
1011-
if not trigger in self._syntax[what][topic]:
1011+
if trigger not in self._syntax[what][topic]:
10121012
self._syntax[what][topic][trigger] = {}
10131013
self._syntax[what][topic][trigger]['reply'] = {}
10141014
self._syntax[what][topic][trigger]['condition'] = {}
@@ -1064,7 +1064,7 @@ def sort_replies(self, thats=False):
10641064
running = self._sort_trigger_set(alltrig)
10651065

10661066
# Save this topic's sorted list.
1067-
if not sortlvl in self._sorted:
1067+
if sortlvl not in self._sorted:
10681068
self._sorted[sortlvl] = {}
10691069
self._sorted[sortlvl][topic] = running
10701070

@@ -1086,15 +1086,15 @@ def _sort_that_triggers(self):
10861086
"""Make a sorted list of triggers that correspond to %Previous groups."""
10871087
self._say("Sorting reverse triggers for %Previous groups...")
10881088

1089-
if not "that_trig" in self._sorted:
1089+
if "that_trig" not in self._sorted:
10901090
self._sorted["that_trig"] = {}
10911091

10921092
for topic in self._thats:
1093-
if not topic in self._sorted["that_trig"]:
1093+
if topic not in self._sorted["that_trig"]:
10941094
self._sorted["that_trig"][topic] = {}
10951095

10961096
for bottrig in self._thats[topic]:
1097-
if not bottrig in self._sorted["that_trig"][topic]:
1097+
if bottrig not in self._sorted["that_trig"][topic]:
10981098
self._sorted["that_trig"][topic][bottrig] = []
10991099
triggers = self._sort_trigger_set(self._thats[topic][bottrig].keys())
11001100
self._sorted["that_trig"][topic][bottrig] = triggers
@@ -1111,7 +1111,7 @@ def _sort_trigger_set(self, triggers):
11111111
match, weight = re.search(RE.weight, trig), 0
11121112
if match:
11131113
weight = int(match.group(1))
1114-
if not weight in prior:
1114+
if weight not in prior:
11151115
prior[weight] = []
11161116

11171117
prior[weight].append(trig)
@@ -1150,7 +1150,7 @@ def _sort_trigger_set(self, triggers):
11501150

11511151
# If this is the first time we've seen this inheritence level,
11521152
# initialize its track structure.
1153-
if not inherits in track:
1153+
if inherits not in track:
11541154
track[inherits] = self._init_sort_track()
11551155

11561156
# Start inspecting the trigger's contents.
@@ -1159,7 +1159,7 @@ def _sort_trigger_set(self, triggers):
11591159
cnt = self._word_count(trig)
11601160
self._say("\t\t\tHas a _ wildcard with " + str(cnt) + " words.")
11611161
if cnt > 1:
1162-
if not cnt in track[inherits]['alpha']:
1162+
if cnt not in track[inherits]['alpha']:
11631163
track[inherits]['alpha'][cnt] = []
11641164
track[inherits]['alpha'][cnt].append(trig)
11651165
else:
@@ -1169,7 +1169,7 @@ def _sort_trigger_set(self, triggers):
11691169
cnt = self._word_count(trig)
11701170
self._say("\t\t\tHas a # wildcard with " + str(cnt) + " words.")
11711171
if cnt > 1:
1172-
if not cnt in track[inherits]['number']:
1172+
if cnt not in track[inherits]['number']:
11731173
track[inherits]['number'][cnt] = []
11741174
track[inherits]['number'][cnt].append(trig)
11751175
else:
@@ -1179,7 +1179,7 @@ def _sort_trigger_set(self, triggers):
11791179
cnt = self._word_count(trig)
11801180
self._say("\t\t\tHas a * wildcard with " + str(cnt) + " words.")
11811181
if cnt > 1:
1182-
if not cnt in track[inherits]['wild']:
1182+
if cnt not in track[inherits]['wild']:
11831183
track[inherits]['wild'][cnt] = []
11841184
track[inherits]['wild'][cnt].append(trig)
11851185
else:
@@ -1188,14 +1188,14 @@ def _sort_trigger_set(self, triggers):
11881188
# Optionals included.
11891189
cnt = self._word_count(trig)
11901190
self._say("\t\t\tHas optionals and " + str(cnt) + " words.")
1191-
if not cnt in track[inherits]['option']:
1191+
if cnt not in track[inherits]['option']:
11921192
track[inherits]['option'][cnt] = []
11931193
track[inherits]['option'][cnt].append(trig)
11941194
else:
11951195
# Totally atomic.
11961196
cnt = self._word_count(trig)
11971197
self._say("\t\t\tTotally atomic and " + str(cnt) + " words.")
1198-
if not cnt in track[inherits]['atomic']:
1198+
if cnt not in track[inherits]['atomic']:
11991199
track[inherits]['atomic'][cnt] = []
12001200
track[inherits]['atomic'][cnt].append(trig)
12011201

@@ -1223,7 +1223,7 @@ def by_length(word1, word2):
12231223
return len(word2) - len(word1)
12241224

12251225
# Initialize the list sort buffer.
1226-
if not "lists" in self._sorted:
1226+
if "lists" not in self._sorted:
12271227
self._sorted["lists"] = {}
12281228
self._sorted["lists"][name] = []
12291229

@@ -1234,7 +1234,7 @@ def by_length(word1, word2):
12341234
for item in items:
12351235
# Count the words.
12361236
cword = self._word_count(item, all=True)
1237-
if not cword in track:
1237+
if cword not in track:
12381238
track[cword] = []
12391239
track[cword].append(item)
12401240

@@ -1355,7 +1355,7 @@ def set_person(self, what, rep):
13551355
def set_uservar(self, user, name, value):
13561356
"""Set a variable for a user."""
13571357

1358-
if not user in self._users:
1358+
if user not in self._users:
13591359
self._users[user] = {"topic": "random"}
13601360

13611361
self._users[user][name] = value
@@ -1581,11 +1581,11 @@ def _format_message(self, msg, botreply=False):
15811581

15821582
def _getreply(self, user, msg, context='normal', step=0):
15831583
# Needed to sort replies?
1584-
if not 'topics' in self._sorted:
1584+
if 'topics' not in self._sorted:
15851585
raise Exception("You forgot to call sort_replies()!")
15861586

15871587
# Initialize the user's profile?
1588-
if not user in self._users:
1588+
if user not in self._users:
15891589
self._users[user] = {'topic': 'random'}
15901590

15911591
# Collect data on the user.
@@ -1595,7 +1595,7 @@ def _getreply(self, user, msg, context='normal', step=0):
15951595
reply = ''
15961596

15971597
# Avoid letting them fall into a missing topic.
1598-
if not topic in self._topics:
1598+
if topic not in self._topics:
15991599
self._warn("User " + user + " was in an empty topic named '" + topic + "'")
16001600
topic = self._users[user]['topic'] = 'random'
16011601

@@ -1608,7 +1608,7 @@ def _getreply(self, user, msg, context='normal', step=0):
16081608
topic = '__begin__'
16091609

16101610
# Initialize this user's history.
1611-
if not '__history__' in self._users[user]:
1611+
if '__history__' not in self._users[user]:
16121612
self._users[user]['__history__'] = {
16131613
'input': [
16141614
'undefined', 'undefined', 'undefined', 'undefined',
@@ -1623,7 +1623,7 @@ def _getreply(self, user, msg, context='normal', step=0):
16231623
}
16241624

16251625
# More topic sanity checking.
1626-
if not topic in self._topics:
1626+
if topic not in self._topics:
16271627
# This was handled before, which would mean topic=random and
16281628
# it doesn't exist. Serious issue!
16291629
return "[ERR: No default topic 'random' was found!]"
@@ -1722,7 +1722,7 @@ def _getreply(self, user, msg, context='normal', step=0):
17221722

17231723
# We found a match, but what if the trigger we've matched
17241724
# doesn't belong to our topic? Find it!
1725-
if not trig in self._topics[topic]:
1725+
if trig not in self._topics[topic]:
17261726
# We have to find it.
17271727
matched = self._find_trigger_by_inheritence(topic, trig)
17281728
else:
@@ -1858,9 +1858,9 @@ def _substitute(self, msg, kind):
18581858
"""Run a kind of substitution on a message."""
18591859

18601860
# Safety checking.
1861-
if not 'lists' in self._sorted:
1861+
if 'lists' not in self._sorted:
18621862
raise Exception("You forgot to call sort_replies()!")
1863-
if not kind in self._sorted["lists"]:
1863+
if kind not in self._sorted["lists"]:
18641864
raise Exception("You forgot to call sort_replies()!")
18651865

18661866
# Get the substitution map.
@@ -1903,7 +1903,7 @@ def _precompile_substitution(self, kind, pattern):
19031903
This will speed up the substitutions that happen at the beginning of
19041904
the reply fetching process. With the default brain, this took the
19051905
time for _substitute down from 0.08s to 0.02s"""
1906-
if not pattern in self._regexc[kind]:
1906+
if pattern not in self._regexc[kind]:
19071907
qm = re.escape(pattern)
19081908
self._regexc[kind][pattern] = {
19091909
"qm": qm,
@@ -2128,7 +2128,7 @@ def _process_tags(self, user, msg, reply, st=[], bst=[], depth=0):
21282128
# Sanity check the value.
21292129
try:
21302130
value = int(value)
2131-
if not var in self._users[user]:
2131+
if var not in self._users[user]:
21322132
# Initialize it.
21332133
self._users[user][var] = 0
21342134
except:

0 commit comments

Comments
 (0)