Skip to content

Commit

Permalink
Pylint alerts corrections as part of intervention experiment #81 (#82)
Browse files Browse the repository at this point in the history
* src\views\setup.py  line-too-long

Line was one letter too long

* src\tools\troubleshoot_db.py  simplifiable-if-expression

if result_proxy.fetchall() == [(123,)] can result in only True or False, the external condition is not needed.
However, if  result_proxy.fetchall() might return Noe, the external condition can translate it to False.

The external condition hurt readability since it takes a bit to verify what it does.
bool is a simpler implementation

See
https://stackoverflow.com/questions/76094401/the-if-expression-can-be-replaced-with-test-simplifiable-if-expression

* src\views\menu.py  broad-exception-caught

Code deliberately catches Exception, after catching KeyboardInterrupt.
However, looking at the protected code it seems that no other exception can be raised.
Hence, instead of narrowing the exception, I removed it.

* src\lib\Config.py  line-too-long

Made the long, yet readable, comment shorter

* src\modules\autocomplete.py  broad-exception-caught

 Code deliberately catches Exception, after catching KeyboardInterrupt.
However, looking at the protected code it seems that no other exception can be raised.
Hence, instead of narrowing the exception, I removed it.

* src\modules\misc.py  broad-exception-caught

Exception is too wide.
os.path.exists does not throw exceptions.
os.makedirs might throw OSError (e.g., in a bad path).

See
https://stackoverflow.com/questions/2383816/how-can-i-make-an-error-verifiy-with-os-makedirs-in-python
As extra safety, though the code checks just before for the directory, catch it too in case a different process will be able to create it before.

* src\views\categories.py  superfluous-parens

Replaced (True) to True

* src\views\import_export.py  line-too-long

Made a readable comment line shorter

* src\views\migration.py  line-too-long

Made the line shorter.
Since the string is also formatted, parenthesis are added for operations precedence.
  • Loading branch information
evidencebp authored Sep 25, 2024
1 parent 688fd28 commit 5476e3a
Show file tree
Hide file tree
Showing 9 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion src/lib/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ def set_default_config_file(self):

self.config['MAIN'] = {
'version': '2.00',
'keyVersion': '1', # Will be used to support legacy key versions if the algorithm changes
'keyVersion': '1', # Will be used to support legacy key versions
# if the algorithm changes
'salt': self.generate_random_salt(),
'clipboardTTL': '15',
'hideSecretTTL': '5',
Expand Down
2 changes: 0 additions & 2 deletions src/modules/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,3 @@ def get_input_autocomplete(message=''):
return input(message).strip()
except KeyboardInterrupt:
return False
except Exception: # Other Exception
return False
2 changes: 1 addition & 1 deletion src/modules/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def create_directory_if_missing(dir_):
return True

return False
except Exception:
except (OSError, FileExistsError):
import sys

print()
Expand Down
2 changes: 1 addition & 1 deletion src/tools/troubleshoot_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def attempt_dummy_encrypted_db(db_path):
connection.execute(text('CREATE TABLE foo (a int)'))
connection.execute(text('INSERT INTO foo (a) VALUES (123)'))
result_proxy = connection.execute(text('SELECT * FROM foo'))
return True if result_proxy.fetchall() == [(123,)] else False
return bool(result_proxy.fetchall() == [(123,)])


def verify_if_dummy_db_is_encrypted(db_path):
Expand Down
2 changes: 1 addition & 1 deletion src/views/categories.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def main_menu():
Categories menu
"""

while (True):
while True:
# Clear screen
clear_screen()

Expand Down
3 changes: 2 additions & 1 deletion src/views/import_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ def import_from_json(path=None, rows=None):
def import_items(rows):
"""
Import items at the following format:
[{'name': '...', 'url': '...', 'login': '...', 'password': '...', 'notes': '...', 'category': '...'}]
[{'name': '...', 'url': '...', 'login': '...'
, 'password': '...', 'notes': '...', 'category': '...'}]
"""

for row in rows:
Expand Down
2 changes: 0 additions & 2 deletions src/views/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ def get_input(message='', secure=False, lowercase=False, check_timer=True, non_l
input_ = input_.lower()
except KeyboardInterrupt:
return False
except Exception: # Other Exception
return False

return input_

Expand Down
3 changes: 2 additions & 1 deletion src/views/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ def migrate(vault_path, config_path, new_vault_path=None):
print()
print('The migration is now complete!')
print('Restart the application to use Vault 2.')
print('Your old vault is stored in `%s`. You can discard this file after ensuring that all your data was migrated properly.' % (vault_path))
print('Your old vault is stored in `%s`. You can discard this file after ensuring that all your data was migrated properly.'
% (vault_path))
print('Your new vault is stored in `%s`.' % (new_vault_path))
print()

Expand Down
3 changes: 2 additions & 1 deletion src/views/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ def initialize(salt):
print("Your vault has been created and encrypted with your master key.")
print("Your unique salt is: %s " % (salt))
print(
"Write it down. If you lose your config file you will need it to unlock your vault.")
"Write it down."
+ " If you lose your config file you will need it to unlock your vault.")

return True

Expand Down

0 comments on commit 5476e3a

Please sign in to comment.