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

Remove unused variables #3029

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

johannaengland
Copy link
Contributor

As #3028 another part to adding F481 to ruff.

Copy link

sonarcloud bot commented Sep 25, 2024

@@ -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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

Copy link
Member

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).

Copy link

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ PYTHON black 992 0 11.87s
✅ PYTHON ruff 987 0 0.1s

See detailed report in MegaLinter reports

MegaLinter is graciously provided by OX Security

Copy link

Test results

    9 files      9 suites   9m 33s ⏱️
2 128 tests 2 128 ✅ 0 💤 0 ❌
3 995 runs  3 995 ✅ 0 💤 0 ❌

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
Copy link
Member

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
Copy link
Member

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:

Suggested change
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()

Comment on lines -175 to -178
configuration = [
'{}={}'.format(key, value)
for key, value in profile.configuration.items()
]
Copy link
Member

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants