-
Notifications
You must be signed in to change notification settings - Fork 39
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
Remove unused variables #3029
base: master
Are you sure you want to change the base?
Remove unused variables #3029
Conversation
Quality Gate passedIssues Measures |
@@ -51,7 +51,7 @@ def on_plugin_load(cls): | |||
@defer.inlineCallbacks | |||
def handle(self): | |||
self._logger.debug("Collecting physical entity data") | |||
need_to_collect = yield self._need_to_collect() | |||
need_to_collect = yield self._need_to_collect() # noqa: F841 - needs work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lunkwill42 I think you can probably write a better comment here on why this needs work
@@ -230,7 +230,7 @@ def check_snmp_version(ip, profile): | |||
def test_napalm_connectivity(ip_address: str, profile: ManagementProfile) -> dict: | |||
"""Tests connectivity of a NAPALM profile and returns a status dictionary""" | |||
try: | |||
with napalm.connect(ip_address, profile) as device: | |||
with napalm.connect(ip_address, profile) as device: # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know enough about napalm to know if this is necessary or not
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a Napalm thing. It's a Python context manager thing. The with
keyword invokes and returns a context manager object. If you need access to the object inside the with
block, you can get it as a variable (in this case, as device
). However, there is no code in the block that directly accesses the context manager, so no need for the assignment.
The object is still created and lives for the duration of the with
block. It's __enter__
method is called as the block starts, and its __exit__
method is called as soon as the block exits (whether it be through a normal control flow or an exception).
🦙 MegaLinter status: ✅ SUCCESS
See detailed report in MegaLinter reports |
Test results 9 files 9 suites 9m 33s ⏱️ Results for commit b25cdab. |
@@ -230,7 +230,7 @@ def check_snmp_version(ip, profile): | |||
def test_napalm_connectivity(ip_address: str, profile: ManagementProfile) -> dict: | |||
"""Tests connectivity of a NAPALM profile and returns a status dictionary""" | |||
try: | |||
with napalm.connect(ip_address, profile) as device: | |||
with napalm.connect(ip_address, profile) as device: # noqa |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not a Napalm thing. It's a Python context manager thing. The with
keyword invokes and returns a context manager object. If you need access to the object inside the with
block, you can get it as a variable (in this case, as device
). However, there is no code in the block that directly accesses the context manager, so no need for the assignment.
The object is still created and lives for the duration of the with
block. It's __enter__
method is called as the block starts, and its __exit__
method is called as soon as the block exits (whether it be through a normal control flow or an exception).
@@ -51,7 +51,7 @@ def on_plugin_load(cls): | |||
@defer.inlineCallbacks | |||
def handle(self): | |||
self._logger.debug("Collecting physical entity data") | |||
need_to_collect = yield self._need_to_collect() | |||
need_to_collect = yield self._need_to_collect() # noqa: F841 - needs work |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My take on it is this. It's that, or create an issue to remember that this should be looked at and fixed, so the two lines can be put back in:
need_to_collect = yield self._need_to_collect() # noqa: F841 - needs work | |
# Temporarily disabled due to consistency issues with some vendors: | |
# need_to_collect = yield self._need_to_collect() |
configuration = [ | ||
'{}={}'.format(key, value) | ||
for key, value in profile.configuration.items() | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice, I wonder how this got through code review - from the original PR it's obviously some half-finished cruft that got left in there by mistake...
As #3028 another part to adding
F481
to ruff.