aws / aws/aws-cli

Refactor: simplify _construct_result in emr createdefaultroles, avoid shadowing builtin list

Open Beginner friendly
#10,572 1 comment 0 reactions 0 assignees View on GitHub
needs-triage
Dominant language
Python
Stars
17.3k
Forks
4.6k
Avg merge
1d 2h
Merged PRs (30d)
13

Description

## Summary

\`awscli/customizations/emr/createdefaultroles.py\` \`_construct_result\` (lines ~208-224) builds its result via a helper, \`_construct_role_and_role_policy_structure\`, that takes a mutable list parameter literally named \`list\` (shadowing the builtin) and mutates it in place across three repetitive calls just to conditionally append a dict.

## Proposed change

Replace the mutating helper with a list comprehension/filter over the three \`(response, policy)\` pairs:
\`\`\`python
return [
{'Role': response['Role'], 'RolePolicy': policy}
for response, policy in responses_and_policies
if response is not None and response['Role'] is not None
]
\`\`\`
This removes the builtin-shadowing parameter name and the mutating helper entirely. Pure refactor, no behavior change.

Contributor guide

Open the contributing guide

Research direction

Read awscli/customizations/emr/createdefaultroles.py around _construct_result (lines ~208-224), then inspect _construct_role_and_role_policy_structure and the three response/policy calls. The work is done when the mutating helper and builtin-shadowing parameter are removed, the result is built from the three pairs, and behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Refactor
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
82/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.