Skip to content

Commit

Permalink
Fix pylint warnings
Browse files Browse the repository at this point in the history
New pylint warnings appeared with code "W0602: Using global for X but
no assignment is done (global-variable-not-assigned)" where X is a
global variable.
In the lines pointed by the warnings, "global" was used inside a
function scope in order to enable assignment of the global variable to
a new value in the function.
The reason for these warnings was that pylint noticed we are using
"global" for the variable X inside a function scope without actually
assigning it to a new value.
Overall that was true for the reported cases and I removed the use of
"global", but there were only two cases were pylint reported a
false-positive. Then we were using "global", but pylint didn't
understand there were an assignments.
In those cases, I disabled the warnings.

Signed-off-by: Martin Vrachev <mvrachev@vmware.com>
  • Loading branch information
MVrachev committed Sep 17, 2021
1 parent 279ac7d commit 47eee7c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 52 deletions.
3 changes: 0 additions & 3 deletions tuf/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,6 @@ def set_console_log_level(log_level=_DEFAULT_CONSOLE_LOG_LEVEL):
# Raise 'securesystems.exceptions.FormatError' if there is a mismatch.
sslib_formats.LOGLEVEL_SCHEMA.check_match(log_level)

# Assign to the global console_handler object.
global console_handler

if console_handler is not None:
console_handler.setLevel(log_level)

Expand Down
51 changes: 2 additions & 49 deletions tuf/roledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,6 @@ def create_roledb_from_root_metadata(root_metadata, repository_name='default'):
# Is 'repository_name' formatted correctly?
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

# Clear the role database.
if repository_name in _roledb_dict:
_roledb_dict[repository_name].clear()
Expand Down Expand Up @@ -176,9 +173,6 @@ def create_roledb(repository_name):
# 'securesystemslib.exceptions.FormatError'.
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name in _roledb_dict or repository_name in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name'
' already exists: ' + repr(repository_name))
Expand Down Expand Up @@ -219,9 +213,6 @@ def remove_roledb(repository_name):
# 'securesystemslib.exceptions.FormatError'.
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
logger.warning('Repository name does not exist:'
' ' + repr(repository_name))
Expand Down Expand Up @@ -294,8 +285,6 @@ def add_role(rolename, roleinfo, repository_name='default'):
# Is 'repository_name' correctly formatted?
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict

# Raises securesystemslib.exceptions.InvalidNameError.
_validate_rolename(rolename)

Expand Down Expand Up @@ -380,9 +369,6 @@ def update_roleinfo(rolename, roleinfo, mark_role_as_dirty=True, repository_name
# Raises securesystemslib.exceptions.InvalidNameError.
_validate_rolename(rolename)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does not' ' exist: ' +
repository_name)
Expand Down Expand Up @@ -432,9 +418,6 @@ def get_dirty_roles(repository_name='default'):
# 'securesystemslib.exceptions.FormatError' if not.
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does'
' not' ' exist: ' + repository_name)
Expand Down Expand Up @@ -475,9 +458,6 @@ def mark_dirty(roles, repository_name='default'):
sslib_formats.NAMES_SCHEMA.check_match(roles)
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does'
' not' ' exist: ' + repository_name)
Expand Down Expand Up @@ -518,9 +498,6 @@ def unmark_dirty(roles, repository_name='default'):
sslib_formats.NAMES_SCHEMA.check_match(roles)
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does'
' not exist: ' + repository_name)
Expand Down Expand Up @@ -623,9 +600,6 @@ def remove_role(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

# 'rolename' was verified to exist in _check_rolename().
# Remove 'rolename' now.
del _roledb_dict[repository_name][rolename]
Expand Down Expand Up @@ -662,9 +636,6 @@ def get_rolenames(repository_name='default'):
# 'securesystemslib.exceptions.FormatError' if it is improperly formatted.
sslib_formats.NAME_SCHEMA.check_match(repository_name)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does'
' not' ' exist: ' + repository_name)
Expand Down Expand Up @@ -725,9 +696,6 @@ def get_roleinfo(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

return copy.deepcopy(_roledb_dict[repository_name][rolename])


Expand Down Expand Up @@ -778,9 +746,6 @@ def get_role_keyids(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

roleinfo = _roledb_dict[repository_name][rolename]

return roleinfo['keyids']
Expand Down Expand Up @@ -830,9 +795,6 @@ def get_role_threshold(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

roleinfo = _roledb_dict[repository_name][rolename]

return roleinfo['threshold']
Expand Down Expand Up @@ -881,9 +843,6 @@ def get_role_paths(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

roleinfo = _roledb_dict[repository_name][rolename]

# Paths won't exist for non-target roles.
Expand Down Expand Up @@ -941,9 +900,6 @@ def get_delegated_rolenames(rolename, repository_name='default'):
# securesystemslib.exceptions.InvalidNameError.
_check_rolename(rolename, repository_name)

global _roledb_dict
global _dirty_roles

# get_roleinfo() raises a 'securesystemslib.exceptions.InvalidNameError' if
# 'repository_name' does not exist in the role database.
roleinfo = get_roleinfo(rolename, repository_name)
Expand Down Expand Up @@ -990,8 +946,8 @@ def clear_roledb(repository_name='default', clear_all=False):
sslib_formats.NAME_SCHEMA.check_match(repository_name)
sslib_formats.BOOLEAN_SCHEMA.check_match(clear_all)

global _roledb_dict
global _dirty_roles
global _roledb_dict # pylint: disable=global-variable-not-assigned
global _dirty_roles # pylint: disable=global-variable-not-assigned

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does not'
Expand Down Expand Up @@ -1030,9 +986,6 @@ def _check_rolename(rolename, repository_name='default'):
# Raises securesystemslib.exceptions.InvalidNameError.
_validate_rolename(rolename)

global _roledb_dict
global _dirty_roles

if repository_name not in _roledb_dict or repository_name not in _dirty_roles:
raise sslib_exceptions.InvalidNameError('Repository name does not'
' exist: ' + repository_name)
Expand Down

0 comments on commit 47eee7c

Please sign in to comment.