pynetbox icon indicating copy to clipboard operation
pynetbox copied to clipboard

Fix Ruff errors add Ruff to pre-commit

Open arthanson opened this issue 5 months ago • 0 comments

Proposed Changes

Add Ruff to pre-commit and fix Ruff errors.

Justification

Ruff can enhance code maintainability and code quality. Currently ruff shows the following issues in pynetbox:

pynetbox/__init__.py:1:38: F401 `pynetbox.core.api.Api` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
  |
1 | from pynetbox.core.api import Api as api
  |                                      ^^^ F401
2 | from pynetbox.core.query import AllocationError, ContentError, RequestError
  |
  = help: Use an explicit re-export: `Api as Api`

pynetbox/__init__.py:2:33: F401 `pynetbox.core.query.AllocationError` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
  |
1 | from pynetbox.core.api import Api as api
2 | from pynetbox.core.query import AllocationError, ContentError, RequestError
  |                                 ^^^^^^^^^^^^^^^ F401
3 |
4 | __version__ = "7.5.0"
  |
  = help: Use an explicit re-export: `AllocationError as AllocationError`

pynetbox/__init__.py:2:50: F401 `pynetbox.core.query.ContentError` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
  |
1 | from pynetbox.core.api import Api as api
2 | from pynetbox.core.query import AllocationError, ContentError, RequestError
  |                                                  ^^^^^^^^^^^^ F401
3 |
4 | __version__ = "7.5.0"
  |
  = help: Use an explicit re-export: `ContentError as ContentError`

pynetbox/__init__.py:2:64: F401 `pynetbox.core.query.RequestError` imported but unused; consider removing, adding to `__all__`, or using a redundant alias
  |
1 | from pynetbox.core.api import Api as api
2 | from pynetbox.core.query import AllocationError, ContentError, RequestError
  |                                                                ^^^^^^^^^^^^ F401
3 |
4 | __version__ = "7.5.0"
  |
  = help: Use an explicit re-export: `RequestError as RequestError`

pynetbox/core/api.py:281:50: E713 [*] Test for membership should be `not in`
    |
279 |         ```
280 |         """
281 |         if not isinstance(branch, Record) or not "schema_id" in dict(branch):
    |                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ E713
282 |             raise ValueError(
283 |                 f"The specified branch is not a valid NetBox branch: {branch}."
    |
    = help: Convert to `not in`

testit2.py:2:44: F401 [*] `pynetbox.models.virtualization.VirtualMachines` imported but unused
  |
1 | import pynetbox
2 | from pynetbox.models.virtualization import VirtualMachines
  |                                            ^^^^^^^^^^^^^^^ F401
3 | from tenacity import retry, stop_after_attempt, wait_exponential, retry_if_result
  |
  = help: Remove unused import: `pynetbox.models.virtualization.VirtualMachines`

tests/unit/test_query.py:64:9: F841 Local variable `expected` is assigned to but never used
   |
62 |             "results": [1, 2, 3, 4],
63 |         }
64 |         expected = call(
   |         ^^^^^^^^ F841
65 |             "http://localhost:8001/api/dcim/devices/",
66 |             params={"offset": 20, "limit": 10},
   |
   = help: Remove assignment to unused variable `expected`

arthanson avatar May 21 '25 20:05 arthanson