You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
defgen_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.
defgen_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) forblacklistinBLACKLISTS]
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.
The text was updated successfully, but these errors were encountered:
acharles7
changed the title
Enhancement remove redundant code using list comprehension
Enhancement: Remove redundant code using list comprehension
Jun 15, 2020
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
tolist
i.eDescribe the solution you'd like
This can be achieved by using list comprehension i.e.
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
comprehensionAdditional context
There are other files in the
bandit
module that requires improvement.The text was updated successfully, but these errors were encountered: