diff --git a/src/backend/InvenTree/InvenTree/tasks.py b/src/backend/InvenTree/InvenTree/tasks.py index 37f8cb2747..20f622380d 100644 --- a/src/backend/InvenTree/InvenTree/tasks.py +++ b/src/backend/InvenTree/InvenTree/tasks.py @@ -278,7 +278,7 @@ class ScheduledTask: func: Callable interval: str - minutes: int = None + minutes: Optional[int] = None MINUTES = 'I' HOURLY = 'H' diff --git a/src/backend/InvenTree/InvenTree/validators.py b/src/backend/InvenTree/InvenTree/validators.py index ed6874b6d1..6b54d99a97 100644 --- a/src/backend/InvenTree/InvenTree/validators.py +++ b/src/backend/InvenTree/InvenTree/validators.py @@ -113,7 +113,7 @@ def validate_overage(value): raise ValidationError(_('Overage value must not be negative')) # Looks like a number - return True + return except (ValueError, InvalidOperation): pass @@ -130,7 +130,7 @@ def validate_overage(value): elif f > 100: raise ValidationError(_('Overage must not exceed 100%')) - return True + return except ValueError: pass diff --git a/src/backend/InvenTree/InvenTree/version.py b/src/backend/InvenTree/InvenTree/version.py index 3e7979966b..64a10ffb1b 100644 --- a/src/backend/InvenTree/InvenTree/version.py +++ b/src/backend/InvenTree/InvenTree/version.py @@ -30,7 +30,7 @@ try: main_repo = Repo(pathlib.Path(__file__).parent.parent.parent.parent.parent) main_commit = main_repo[main_repo.head()] -except (ImportError, ModuleNotFoundError): +except ImportError: logger.warning( 'Warning: Dulwich module not found, git information will not be available.' ) diff --git a/src/backend/InvenTree/common/currency.py b/src/backend/InvenTree/common/currency.py index c44d5019aa..a83f13d157 100644 --- a/src/backend/InvenTree/common/currency.py +++ b/src/backend/InvenTree/common/currency.py @@ -3,6 +3,7 @@ import decimal import logging import math +from typing import Optional from django.core.cache import cache from django.core.exceptions import ValidationError @@ -143,7 +144,7 @@ def validate_currency_codes(value): return list(valid_currencies) -def currency_exchange_plugins() -> list: +def currency_exchange_plugins() -> Optional[list]: """Return a list of plugin choices which can be used for currency exchange.""" try: from plugin import registry diff --git a/src/backend/InvenTree/common/notifications.py b/src/backend/InvenTree/common/notifications.py index 8988f845f3..6021583235 100644 --- a/src/backend/InvenTree/common/notifications.py +++ b/src/backend/InvenTree/common/notifications.py @@ -3,6 +3,7 @@ import logging from dataclasses import dataclass from datetime import timedelta +from typing import Optional from django.contrib.auth import get_user_model from django.contrib.auth.models import Group @@ -315,7 +316,7 @@ class NotificationBody: name: str slug: str message: str - template: str = None + template: Optional[str] = None class InvenTreeNotificationBodies: diff --git a/src/backend/InvenTree/common/tasks.py b/src/backend/InvenTree/common/tasks.py index aa58f22cc2..55d358b383 100644 --- a/src/backend/InvenTree/common/tasks.py +++ b/src/backend/InvenTree/common/tasks.py @@ -50,7 +50,9 @@ def update_news_feed(): return # News feed isn't defined, no need to continue - if not settings.INVENTREE_NEWS_URL or type(settings.INVENTREE_NEWS_URL) != str: + if not settings.INVENTREE_NEWS_URL or not isinstance( + settings.INVENTREE_NEWS_URL, str + ): return # Fetch and parse feed diff --git a/src/backend/InvenTree/company/models.py b/src/backend/InvenTree/company/models.py index ba891c5feb..3a0c21808a 100644 --- a/src/backend/InvenTree/company/models.py +++ b/src/backend/InvenTree/company/models.py @@ -1046,11 +1046,14 @@ class SupplierPriceBreak(common.models.PriceBreak): def after_save_supplier_price(sender, instance, created, **kwargs): """Callback function when a SupplierPriceBreak is created or updated.""" if ( - InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) - and not InvenTree.ready.isImportingData() + ( + InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) + and not InvenTree.ready.isImportingData() + ) + and instance.part + and instance.part.part ): - if instance.part and instance.part.part: - instance.part.part.schedule_pricing_update(create=True) + instance.part.part.schedule_pricing_update(create=True) @receiver( @@ -1061,8 +1064,11 @@ def after_save_supplier_price(sender, instance, created, **kwargs): def after_delete_supplier_price(sender, instance, **kwargs): """Callback function when a SupplierPriceBreak is deleted.""" if ( - InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) - and not InvenTree.ready.isImportingData() + ( + InvenTree.ready.canAppAccessDatabase(allow_test=settings.TESTING_PRICING) + and not InvenTree.ready.isImportingData() + ) + and instance.part + and instance.part.part ): - if instance.part and instance.part.part: - instance.part.part.schedule_pricing_update(create=False) + instance.part.part.schedule_pricing_update(create=False) diff --git a/src/backend/InvenTree/importer/operations.py b/src/backend/InvenTree/importer/operations.py index 6afa7d08c4..3338e6d7d2 100644 --- a/src/backend/InvenTree/importer/operations.py +++ b/src/backend/InvenTree/importer/operations.py @@ -36,7 +36,7 @@ def load_data_file(data_file, file_format=None): try: data = file_object.read() - except (OSError, FileNotFoundError): + except OSError: raise ValidationError(_('Failed to open data file')) # Excel formats expect binary data diff --git a/src/backend/InvenTree/plugin/base/barcodes/api.py b/src/backend/InvenTree/plugin/base/barcodes/api.py index d415be58b9..0170267825 100644 --- a/src/backend/InvenTree/plugin/base/barcodes/api.py +++ b/src/backend/InvenTree/plugin/base/barcodes/api.py @@ -57,7 +57,7 @@ class BarcodeView(CreateAPIView): return # Ensure that the response data is stringified first, otherwise cannot be JSON encoded - if type(response) is dict: + if isinstance(response, dict): response = {key: str(value) for key, value in response.items()} elif response is None: pass @@ -65,7 +65,7 @@ class BarcodeView(CreateAPIView): response = str(response) # Ensure that the context data is stringified first, otherwise cannot be JSON encoded - if type(context) is dict: + if isinstance(context, dict): context = {key: str(value) for key, value in context.items()} elif context is None: pass