rope
rope copied to clipboard
Refactoring idea: extract sublist to method/variable refactoring from container literals/function arguments
Given, a collection literal like so:
actions = [
'1. Walk Forward',
'2. Evade',
f'3. {attack_name}',
'4. Flee',
]
or a function call:
action = env.user_input_choices(
'Choose what to do:',
'1. Walk Forward',
'2. Evade',
f'3. {attack_name}',
'4. Flee',
)
or similar constructs with:
- [ ] list literal
- [ ] tuple literal
- [ ] dict literal
- [ ] set literal
- [ ] function call argument list
When I select a partial list like the following:
'2. Evade',
f'3. {attack_name}',
and perform the following actions:
- [ ] extract refactoring
- [ ] variable refactoring
Then, we should extract the sub-list/set/dict/tuple with the appropriate concatenation operator, like so:
extracted_var = [
'2. Evade',
f'3. {attack_name}',
]
actions = [
'1. Walk Forward',
] + extracted_var + [
'4. Flee',
]
or:
def extracted_function(attack_name):
new_var = [
'2. Evade',
f'3. {attack_name}',
]
actions = [
'1. Walk Forward',
*extracted_function(attack_name),
'4. Flee',
]
Great idea :)