Skip to content

Commit

Permalink
Closes #17951: Extend Ruff ruleset
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Nov 7, 2024
1 parent 812ce84 commit a183048
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def copy_site_assignments(apps, schema_editor):
termination_id=models.F('provider_network_id')
)


class Migration(migrations.Migration):

dependencies = [
Expand Down
2 changes: 1 addition & 1 deletion netbox/circuits/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def setUpTestData(cls):
}


class TestCase(ViewTestCases.PrimaryObjectViewTestCase):
class TestCase(ViewTestCases.PrimaryObjectViewTestCase):
model = CircuitTermination

@classmethod
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/forms/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def clean(self):
from extras.scripts import get_module_and_script
module_name, script_name = action_object.split('.', 1)
try:
module, script = get_module_and_script(module_name, script_name)
script = get_module_and_script(module_name, script_name)[1]
except ObjectDoesNotExist:
raise forms.ValidationError(_("Script {name} not found").format(name=action_object))
self.instance.action_object = script
Expand Down
2 changes: 1 addition & 1 deletion netbox/extras/management/commands/runscript.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def handle(self, *args, **options):
data = {}

module_name, script_name = script.split('.', 1)
module, script_obj = get_module_and_script(module_name, script_name)
script_obj = get_module_and_script(module_name, script_name)[1]
script = script_obj.python_class

# Take user from command line if provided and exists, other
Expand Down
4 changes: 2 additions & 2 deletions netbox/extras/migrations/0109_script_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def get_python_name(scriptmodule):
"""
Return the Python name of a ScriptModule's file on disk.
"""
path, filename = os.path.split(scriptmodule.file_path)
filename = os.path.split(scriptmodule.file_path)[0]
return os.path.splitext(filename)[0]


Expand Down Expand Up @@ -128,7 +128,7 @@ def update_event_rules(apps, schema_editor):

for eventrule in EventRule.objects.filter(action_object_type=scriptmodule_ct):
name = eventrule.action_parameters.get('script_name')
obj, created = Script.objects.get_or_create(
obj, __ = Script.objects.get_or_create(
module_id=eventrule.action_object_id,
name=name,
defaults={'is_executable': False}
Expand Down
4 changes: 2 additions & 2 deletions netbox/ipam/lookups.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ def get_prep_lookup(self):
return self.rhs

def as_sql(self, qn, connection):
lhs, lhs_params = self.process_lhs(qn, connection)
rhs, rhs_params = self.process_rhs(qn, connection)
lhs = self.process_lhs(qn, connection)[0]
rhs_params = self.process_rhs(qn, connection)[1]
with_mask, without_mask = [], []
for address in rhs_params[0]:
if '/' in address:
Expand Down
6 changes: 3 additions & 3 deletions netbox/ipam/tests/test_ordering.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_prefix_vrf_ordering(self):
"""
This is a very basic test, which tests both prefixes without VRFs and prefixes with VRFs
"""
vrf1, vrf2, vrf3 = list(VRF.objects.all())
vrf1, vrf2 = VRF.objects.all()[:2]
prefixes = (
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/16')),
Prefix(status=PrefixStatusChoices.STATUS_ACTIVE, vrf=None, prefix=netaddr.IPNetwork('192.168.0.0/24')),
Expand Down Expand Up @@ -106,7 +106,7 @@ def test_prefix_complex_ordering(self):
VRF A:10.1.1.0/24
None: 192.168.0.0/16
"""
vrf1, vrf2, vrf3 = list(VRF.objects.all())
vrf1 = VRF.objects.first()
prefixes = [
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/8')),
Prefix(status=PrefixStatusChoices.STATUS_CONTAINER, vrf=None, prefix=netaddr.IPNetwork('10.0.0.0/16')),
Expand All @@ -130,7 +130,7 @@ def test_address_vrf_ordering(self):
"""
This function tests ordering with the inclusion of vrfs
"""
vrf1, vrf2, vrf3 = list(VRF.objects.all())
vrf1, vrf2 = VRF.objects.all()[:2]
addresses = (
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.0.1/24')),
IPAddress(status=IPAddressStatusChoices.STATUS_ACTIVE, vrf=vrf1, address=netaddr.IPNetwork('10.0.1.1/24')),
Expand Down
2 changes: 1 addition & 1 deletion netbox/netbox/authentication/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def get_object_permissions(self, user_obj):
return perms

def has_perm(self, user_obj, perm, obj=None):
app_label, action, model_name = resolve_permission(perm)
app_label, __, model_name = resolve_permission(perm)

# Superusers implicitly have all permissions
if user_obj.is_active and user_obj.is_superuser:
Expand Down
1 change: 0 additions & 1 deletion netbox/netbox/tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,6 @@ def test_get_plugin_config(self):
self.assertEqual(get_plugin_config(plugin, 'bar'), None)
self.assertEqual(get_plugin_config(plugin, 'bar', default=456), 456)


def test_events_pipeline(self):
"""
Check that events pipeline is registered.
Expand Down
2 changes: 1 addition & 1 deletion netbox/netbox/views/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def handler_500(request, template_name=ERROR_500_TEMPLATE_NAME):
template = loader.get_template(template_name)
except TemplateDoesNotExist:
return HttpResponseServerError('<h1>Server Error (500)</h1>', content_type='text/html')
type_, error, traceback = sys.exc_info()
type_, error = sys.exc_info()[:2]

return HttpResponseServerError(template.render({
'error': error,
Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/error_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def handle_rest_api_exception(request, *args, **kwargs):
"""
Handle exceptions and return a useful error message for REST API requests.
"""
type_, error, traceback = sys.exc_info()
type_, error = sys.exc_info()[:2]
data = {
'error': str(error),
'exception': type_.__name__,
Expand Down
2 changes: 1 addition & 1 deletion netbox/utilities/tests/test_counters.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def test_interface_count_move(self):

@override_settings(EXEMPT_VIEW_PERMISSIONS=['*'])
def test_mptt_child_delete(self):
device1, device2 = Device.objects.all()
device1 = Device.objects.first()
inventory_item1 = InventoryItem.objects.create(device=device1, name='Inventory Item 1')
InventoryItem.objects.create(device=device1, name='Inventory Item 2', parent=inventory_item1)
device1.refresh_from_db()
Expand Down
2 changes: 0 additions & 2 deletions netbox/virtualization/api/serializers_/clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,5 +80,3 @@ def get_scope(self, obj):
serializer = get_serializer_for_model(obj.scope)
context = {'request': self.context['request']}
return serializer(obj.scope, nested=True, context=context).data


2 changes: 1 addition & 1 deletion netbox/virtualization/graphql/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def scope(self) -> Annotated[Union[
Annotated["SiteGroupType", strawberry.lazy('dcim.graphql.types')],
Annotated["SiteType", strawberry.lazy('dcim.graphql.types')],
], strawberry.union("ClusterScopeType")] | None:
return self.scope
return self.scope


@strawberry_django.type(
Expand Down
22 changes: 11 additions & 11 deletions netbox/virtualization/migrations/0044_cluster_scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@


def copy_site_assignments(apps, schema_editor):
"""
Copy site ForeignKey values to the scope GFK.
"""
ContentType = apps.get_model('contenttypes', 'ContentType')
Cluster = apps.get_model('virtualization', 'Cluster')
Site = apps.get_model('dcim', 'Site')

Cluster.objects.filter(site__isnull=False).update(
scope_type=ContentType.objects.get_for_model(Site),
scope_id=models.F('site_id')
)
"""
Copy site ForeignKey values to the scope GFK.
"""
ContentType = apps.get_model('contenttypes', 'ContentType')
Cluster = apps.get_model('virtualization', 'Cluster')
Site = apps.get_model('dcim', 'Site')

Cluster.objects.filter(site__isnull=False).update(
scope_type=ContentType.objects.get_for_model(Site),
scope_id=models.F('site_id')
)


class Migration(migrations.Migration):
Expand Down
2 changes: 2 additions & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
[lint]
extend-select = ["E1", "E2", "E3", "W"]
ignore = ["E501", "F403", "F405"]
preview = true

0 comments on commit a183048

Please sign in to comment.