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

Fixing Linter errors: undefined-variables<E0602>. #1999

Merged
merged 13 commits into from
Sep 16, 2020

Conversation

kevinclark19a
Copy link
Contributor

Description


PR information

  • The title of the PR is clear and informative.
  • There are a small number of commits, each of which has an informative message. This means that previously merged commits do not appear in the history of the PR. For information on cleaning up the commits in your pull request, see this page.
  • Except for special cases involving multiple contributors, the PR is started from a fork of the main repository, not a branch.
  • If applicable, the PR references the bug/issue that it fixes in the description.
  • New Unit tests were added for the changes made and Travis.CI is passing.

Quality of Code and Contribution Guidelines

@@ -58,7 +59,7 @@ def publish_hostname(self, hostname):
Restart NetworkManager first before publishing hostname
"""
shellutil.run("service NetworkManager restart")
super(RedhatOSUtil, self).publish_hostname(hostname) # pylint: disable=E0602
super(IosxeOSUtil, self).publish_hostname(hostname)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like it was copy-pasted from Redhat. Anyone know if this is the case?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure, most of these distro-specific modules that are not endorsed came from external contributors.

@@ -79,13 +80,13 @@ def get_instance_id(self):
If that is missing, then extracts from dmidecode
If nothing works (for old VMs), return the empty string
'''
if os.path.isfile(PRODUCT_ID_FILE): # pylint: disable=E0602
if os.path.isfile(PRODUCT_ID_FILE):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

os and PRODUCT_ID_FILE both seem like they were straight-up just not imported into this module...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol whoever wrote the code (and reviewed it) didnt do a good job :p

rc, s = shellutil.run_get_output(DMIDECODE_CMD) # pylint: disable=E0602,C0103
if rc != 0 or UUID_PATTERN.match(s) is None: # pylint: disable=E0602
rc, s = shellutil.run_get_output(DMIDECODE_CMD) # pylint: disable=C0103
if rc != 0 or UUID_PATTERN.match(s) is None:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, this time with DMIDECODE_CMD and UUID_PATTERN.

@@ -126,7 +126,7 @@ def restart_ssh_service(self): # pylint: disable=R1710
if os.path.exists("/etc/init.d/sshd"): # pylint: disable=R1705
return shellutil.run("/etc/init.d/sshd restart", chk_err=True)
else:
logger.warn("sshd service does not exists", username) # pylint: disable=E0602
logger.warn("sshd service does not exists")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like this was just copy-pasted from a method with username in scope.

@@ -25,16 +25,38 @@

bytebuffer = memoryview # pylint: disable=C0103

# We aren't using these imports in this file, but we want them to be available
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for cleaning these up!

pgombar
pgombar previously approved these changes Sep 8, 2020
ustr = unicode # Rename Python2 unicode to ustr
bytebuffer = buffer
range = xrange
int = long
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these all for Py2?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that's right.

# to import from this module in others.
# Additionally, python2 doesn't have this, so we need to disable import-error
# as well.
from builtins import int, range # pylint: disable=unused-import,import-error
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wont this throw if py2 doesnt have these?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just off screen in the GitHub view, but we're in a if sys.version_info[0] == 3:, so this shouldn't be executed in a python2 env.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh got it! Thanks!

@@ -79,13 +80,13 @@ def get_instance_id(self):
If that is missing, then extracts from dmidecode
If nothing works (for old VMs), return the empty string
'''
if os.path.isfile(PRODUCT_ID_FILE): # pylint: disable=E0602
if os.path.isfile(PRODUCT_ID_FILE):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol whoever wrote the code (and reviewed it) didnt do a good job :p

Copy link
Member

@narrieta narrieta left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a couple of questions

narrieta
narrieta previously approved these changes Sep 15, 2020
@kevinclark19a kevinclark19a merged commit 6c10ad7 into Azure:develop Sep 16, 2020
@kevinclark19a kevinclark19a deleted the LinterUndefinedVariables branch September 16, 2020 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants