Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: Remove redundant code using list comprehension #620

Open
acharles7 opened this issue Jun 14, 2020 · 0 comments · May be fixed by #621
Open

Enhancement: Remove redundant code using list comprehension #620

acharles7 opened this issue Jun 14, 2020 · 0 comments · May be fixed by #621
Labels
enhancement New feature or request

Comments

@acharles7
Copy link

Is your feature request related to a problem? Please describe.
Currently, In bandit/blacklists/imports.py There is redundant appending code for every blacklist items, that we can easily remove using list comprehension. i.e. appending blacklists items dict to list i.e

def gen_blacklist():
    sets = []
    sets.append(utils.build_conf_dict(
        'import_telnetlib', 'B401', ['telnetlib'],
        'A telnet-related module is being imported.  Telnet is '
        'considered insecure. Use SSH or some other encrypted protocol.',
        'HIGH'
        ))

    sets.append(utils.build_conf_dict(
        'import_ftplib', 'B402', ['ftplib'],
        'A FTP-related module is being imported.  FTP is considered '
        'insecure. Use SSH/SFTP/SCP or some other encrypted protocol.',
        'HIGH'
        ))
    ...
    ...
    return {'Import': sets, 'ImportFrom': sets, 'Call': sets}

Describe the solution you'd like
This can be achieved by using list comprehension i.e.

def gen_blacklist2():
    
    BLACKLISTS = [
        ['import_telnetlib', 
         'B401', 
         ['telnetlib'],
         'A telnet-related module is being imported.  Telnet is '
         'considered insecure. Use SSH or some other encrypted protocol.',
         'HIGH'],
        
        ['import_ftplib', 
         'B402', 
         ['ftplib'],
         'A FTP-related module is being imported.  FTP is considered '
         'insecure. Use SSH/SFTP/SCP or some other encrypted protocol.',
         'HIGH'],
       ...
    sets = [utils.build_conf_dict(*blacklist) for blacklist in BLACKLISTS] 
    return {'Import': sets, 'ImportFrom': sets, 'Call': sets}
        

If this is done for purpose then ignore this issue otherwise it is nice to have code in list comprehension for easy to read and understand.
I am happy to make PR. Let me know if its a good idea to have list comprehension

Describe alternatives you've considered
dictionary comprehension

Additional context
There are other files in the bandit module that requires improvement.

@acharles7 acharles7 linked a pull request Jun 14, 2020 that will close this issue
@acharles7 acharles7 changed the title Enhancement remove redundant code using list comprehension Enhancement: Remove redundant code using list comprehension Jun 15, 2020
@ericwb ericwb added the enhancement New feature or request label Nov 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants