Skip to content

Commit 33cdbe7

Browse files
committed
some list stuff
Signed-off-by: René <snooz@posteo.de>
1 parent f0aeca5 commit 33cdbe7

File tree

9 files changed

+20
-38
lines changed

9 files changed

+20
-38
lines changed

src/robot/libraries/BuiltIn.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,19 +1021,19 @@ def should_not_contain(self, container, item, msg=None, values=True,
10211021
if is_string(container):
10221022
container = container.casefold()
10231023
elif is_list_like(container):
1024-
container = set(x.casefold() if is_string(x) else x for x in container)
1024+
container = {x.casefold() if is_string(x) else x for x in container}
10251025
if strip_spaces and is_string(item):
10261026
item = self._strip_spaces(item, strip_spaces)
10271027
if is_string(container):
10281028
container = self._strip_spaces(container, strip_spaces)
10291029
elif is_list_like(container):
1030-
container = set(self._strip_spaces(x, strip_spaces) for x in container)
1030+
container = {self._strip_spaces(x, strip_spaces) for x in container}
10311031
if collapse_spaces and is_string(item):
10321032
item = self._collapse_spaces(item)
10331033
if is_string(container):
10341034
container = self._collapse_spaces(container)
10351035
elif is_list_like(container):
1036-
container = set(self._collapse_spaces(x) for x in container)
1036+
container = {self._collapse_spaces(x) for x in container}
10371037
if item in container:
10381038
raise AssertionError(self._get_string_msg(orig_container, item, msg,
10391039
values, 'contains'))
@@ -1077,19 +1077,19 @@ def should_contain(self, container, item, msg=None, values=True,
10771077
if is_string(container):
10781078
container = container.casefold()
10791079
elif is_list_like(container):
1080-
container = set(x.casefold() if is_string(x) else x for x in container)
1080+
container = {x.casefold() if is_string(x) else x for x in container}
10811081
if strip_spaces and is_string(item):
10821082
item = self._strip_spaces(item, strip_spaces)
10831083
if is_string(container):
10841084
container = self._strip_spaces(container, strip_spaces)
10851085
elif is_list_like(container):
1086-
container = set(self._strip_spaces(x, strip_spaces) for x in container)
1086+
container = {self._strip_spaces(x, strip_spaces) for x in container}
10871087
if collapse_spaces and is_string(item):
10881088
item = self._collapse_spaces(item)
10891089
if is_string(container):
10901090
container = self._collapse_spaces(container)
10911091
elif is_list_like(container):
1092-
container = set(self._collapse_spaces(x) for x in container)
1092+
container = {self._collapse_spaces(x) for x in container}
10931093
if item not in container:
10941094
raise AssertionError(self._get_string_msg(orig_container, item, msg,
10951095
values, 'does not contain'))
@@ -1132,19 +1132,19 @@ def should_contain_any(self, container, *items, **configuration):
11321132
if is_string(container):
11331133
container = container.casefold()
11341134
elif is_list_like(container):
1135-
container = set(x.casefold() if is_string(x) else x for x in container)
1135+
container = {x.casefold() if is_string(x) else x for x in container}
11361136
if strip_spaces:
11371137
items = [self._strip_spaces(x, strip_spaces) for x in items]
11381138
if is_string(container):
11391139
container = self._strip_spaces(container, strip_spaces)
11401140
elif is_list_like(container):
1141-
container = set(self._strip_spaces(x, strip_spaces) for x in container)
1141+
container = {self._strip_spaces(x, strip_spaces) for x in container}
11421142
if collapse_spaces:
11431143
items = [self._collapse_spaces(x) for x in items]
11441144
if is_string(container):
11451145
container = self._collapse_spaces(container)
11461146
elif is_list_like(container):
1147-
container = set(self._collapse_spaces(x) for x in container)
1147+
container = {self._collapse_spaces(x) for x in container}
11481148
if not any(item in container for item in items):
11491149
msg = self._get_string_msg(orig_container,
11501150
seq2str(items, lastsep=' or '),
@@ -1190,19 +1190,19 @@ def should_not_contain_any(self, container, *items, **configuration):
11901190
if is_string(container):
11911191
container = container.casefold()
11921192
elif is_list_like(container):
1193-
container = set(x.casefold() if is_string(x) else x for x in container)
1193+
container = {x.casefold() if is_string(x) else x for x in container}
11941194
if strip_spaces:
11951195
items = [self._strip_spaces(x, strip_spaces) for x in items]
11961196
if is_string(container):
11971197
container = self._strip_spaces(container, strip_spaces)
11981198
elif is_list_like(container):
1199-
container = set(self._strip_spaces(x, strip_spaces) for x in container)
1199+
container = {self._strip_spaces(x, strip_spaces) for x in container}
12001200
if collapse_spaces:
12011201
items = [self._collapse_spaces(x) for x in items]
12021202
if is_string(container):
12031203
container = self._collapse_spaces(container)
12041204
elif is_list_like(container):
1205-
container = set(self._collapse_spaces(x) for x in container)
1205+
container = {self._collapse_spaces(x) for x in container}
12061206
if any(item in container for item in items):
12071207
msg = self._get_string_msg(orig_container,
12081208
seq2str(items, lastsep=' or '),
@@ -3150,7 +3150,6 @@ def comment(self, *messages):
31503150
contain non-existing variables. If you are interested about variable
31513151
values, you can use the `Log` or `Log Many` keywords.
31523152
"""
3153-
pass
31543153

31553154
def set_log_level(self, level):
31563155
"""Sets the log threshold to the specified level and returns the old level.
@@ -4000,7 +3999,6 @@ class RobotNotRunningError(AttributeError):
40003999
May later be based directly on Exception, so new code should except
40014000
this exception explicitly.
40024001
"""
4003-
pass
40044002

40054003

40064004
def register_run_keyword(library, keyword, args_to_process=0, deprecation_warning=True):

src/robot/libraries/Collections.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ def append_to_list(self, list_, *values):
4545
| ${L2} = ['a', 'b', 'x', 'y', 'z']
4646
"""
4747
self._validate_list(list_)
48-
for value in values:
49-
list_.append(value)
48+
list_.extend(values)
5049

5150
def insert_into_list(self, list_, index, value):
5251
"""Inserts ``value`` into ``list`` to the position specified with ``index``.
@@ -159,10 +158,7 @@ def remove_duplicates(self, list_):
159158
duplicates. Number of the removed duplicates is logged.
160159
"""
161160
self._validate_list(list_)
162-
ret = []
163-
for item in list_:
164-
if item not in ret:
165-
ret.append(item)
161+
ret = list(dict.fromkeys(list_))
166162
removed = len(list_) - len(ret)
167163
logger.info(f'{removed} duplicate{s(removed)} removed.')
168164
return ret

src/robot/model/body.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,12 +281,10 @@ class Body(BaseBody['Keyword', 'For', 'While', 'If', 'Try', 'Var', 'Return',
281281
282282
Body contains the keywords and other structures such as FOR loops.
283283
"""
284-
pass
285284

286285

287286
class BranchType(Generic[IT]):
288287
"""Class that wrapps `Generic` as python doesn't allow multple generic inheritance"""
289-
pass
290288

291289

292290
class BaseBranches(BaseBody[KW, F, W, I, T, V, R, C, B, M, E], BranchType[IT]):

src/robot/model/visitor.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,9 @@ def start_suite(self, suite: 'TestSuite') -> 'bool|None':
139139
140140
Can return explicit ``False`` to stop visiting.
141141
"""
142-
pass
143142

144143
def end_suite(self, suite: 'TestSuite'):
145144
"""Called when a suite ends. Default implementation does nothing."""
146-
pass
147145

148146
def visit_test(self, test: 'TestCase'):
149147
"""Implements traversing through tests.
@@ -164,11 +162,9 @@ def start_test(self, test: 'TestCase') -> 'bool|None':
164162
165163
Can return explicit ``False`` to stop visiting.
166164
"""
167-
pass
168165

169166
def end_test(self, test: 'TestCase'):
170167
"""Called when a test ends. Default implementation does nothing."""
171-
pass
172168

173169
def visit_keyword(self, keyword: 'Keyword'):
174170
"""Implements traversing through keywords.
@@ -576,7 +572,6 @@ def start_body_item(self, item: 'BodyItem') -> 'bool|None':
576572
Can return explicit ``False`` to stop visiting. Default implementation does
577573
nothing.
578574
"""
579-
pass
580575

581576
def end_body_item(self, item: 'BodyItem'):
582577
"""Called, by default, when keywords, messages or control structures end.
@@ -587,4 +582,3 @@ def end_body_item(self, item: 'BodyItem'):
587582
588583
Default implementation does nothing.
589584
"""
590-
pass

src/robot/result/flattenkeywordmatcher.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,7 @@ def validate_flatten_keyword(options):
2424
# TODO: Deprecate 'foritem' in RF 6.1!
2525
if low == 'foritem':
2626
low = 'iteration'
27-
if not (low in ('for', 'while', 'iteration') or
28-
low.startswith('name:') or
29-
low.startswith('tag:')):
27+
if not (low in ('for', 'while', 'iteration') or low.startswith(('name:', 'tag:'))):
3028
raise DataError(f"Expected 'FOR', 'WHILE', 'ITERATION', 'TAG:<pattern>' or "
3129
f"'NAME:<pattern>', got '{opt}'.")
3230

src/robot/result/model.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ class Branches(model.BaseBranches['Keyword', 'For', 'While', 'If', 'Try', 'Var',
7171

7272
class IterationType(Generic[FW]):
7373
"""Class that wrapps `Generic` as python doesn't allow multple generic inheritance"""
74-
pass
7574

7675

7776
class Iterations(model.BaseBody['Keyword', 'For', 'While', 'If', 'Try', 'Var', 'Return',

src/robot/running/arguments/argumentvalidator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def __init__(self, arg_spec: 'ArgumentSpec'):
2929
self.arg_spec = arg_spec
3030

3131
def validate(self, positional, named, dryrun=False):
32-
named = set(name for name, value in named)
32+
named = {name for name, value in named}
3333
if dryrun and (any(is_list_variable(arg) for arg in positional) or
3434
any(is_dict_variable(arg) for arg in named)):
3535
return

src/robot/running/namespace.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,9 @@ def _get_explicit_runner(self, name):
451451
for owner_name, kw_name in self._get_owner_and_kw_names(name):
452452
for owner in chain(self.libraries.values(), self.resources.values()):
453453
if eq(owner.name, owner_name) and kw_name in owner.handlers:
454-
for handler in owner.handlers.get_handlers(kw_name):
455-
handlers_and_names.append((handler, kw_name))
454+
handlers_and_names.extend(
455+
[(handler, kw_name) for handler in owner.handlers.get_handlers(kw_name)]
456+
)
456457
if not handlers_and_names:
457458
return None
458459
if len(handlers_and_names) == 1:

src/robot/utils/setter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,6 @@ class SetterAwareType(type):
8787
def __new__(cls, name, bases, dct):
8888
if '__slots__' in dct:
8989
slots = list(dct['__slots__'])
90-
for item in dct.values():
91-
if isinstance(item, setter):
92-
slots.append(item.attr_name)
90+
slots.extend([item.attr_name for item in dct.values() if isinstance(item, setter)])
9391
dct['__slots__'] = slots
9492
return type.__new__(cls, name, bases, dct)

0 commit comments

Comments
 (0)