mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Linting fixes (#6906)
* Python linting fixes - Prefix unused loop variable * Fix unneccesary f-string * Remove old 'pass' statement * Fix return type * Simplify if statement * Fix shadowing of builtin * Simplify is_bool function * Improve type hitning for increment_serial_number * Fix shadowing * Remove unused argument * Cleanup if statement * remove unused argument * Update type hinting - Pipe not available until python 3.10
This commit is contained in:
parent
c65f7dce14
commit
c6f178af72
@ -347,7 +347,7 @@ def get_secret_key():
|
|||||||
|
|
||||||
# Create a random key file
|
# Create a random key file
|
||||||
options = string.digits + string.ascii_letters + string.punctuation
|
options = string.digits + string.ascii_letters + string.punctuation
|
||||||
key = ''.join([random.choice(options) for i in range(100)])
|
key = ''.join([random.choice(options) for _idx in range(100)])
|
||||||
secret_key_file.write_text(key)
|
secret_key_file.write_text(key)
|
||||||
|
|
||||||
logger.debug("Loading SECRET_KEY from '%s'", secret_key_file)
|
logger.debug("Loading SECRET_KEY from '%s'", secret_key_file)
|
||||||
|
@ -95,7 +95,7 @@ def from_engineering_notation(value):
|
|||||||
"""
|
"""
|
||||||
value = str(value).strip()
|
value = str(value).strip()
|
||||||
|
|
||||||
pattern = f'(\d+)([a-zA-Z]+)(\d+)(.*)'
|
pattern = '(\d+)([a-zA-Z]+)(\d+)(.*)'
|
||||||
|
|
||||||
if match := re.match(pattern, value):
|
if match := re.match(pattern, value):
|
||||||
left, prefix, right, suffix = match.groups()
|
left, prefix, right, suffix = match.groups()
|
||||||
@ -198,7 +198,6 @@ def convert_physical_value(value: str, unit: str = None, strip_units=True):
|
|||||||
break
|
break
|
||||||
except Exception as exc:
|
except Exception as exc:
|
||||||
value = None
|
value = None
|
||||||
pass
|
|
||||||
|
|
||||||
if value is None:
|
if value is None:
|
||||||
if unit:
|
if unit:
|
||||||
|
@ -20,7 +20,7 @@ class InvenTreeExchange(SimpleExchangeBackend):
|
|||||||
|
|
||||||
name = 'InvenTreeExchange'
|
name = 'InvenTreeExchange'
|
||||||
|
|
||||||
def get_rates(self, **kwargs) -> None:
|
def get_rates(self, **kwargs) -> dict:
|
||||||
"""Set the requested currency codes and get rates."""
|
"""Set the requested currency codes and get rates."""
|
||||||
from common.models import InvenTreeSetting
|
from common.models import InvenTreeSetting
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
|
@ -17,11 +17,10 @@ class InvenTreeDateFilter(rest_filters.DateFilter):
|
|||||||
|
|
||||||
def filter(self, qs, value):
|
def filter(self, qs, value):
|
||||||
"""Override the filter method to handle timezones correctly."""
|
"""Override the filter method to handle timezones correctly."""
|
||||||
if settings.USE_TZ:
|
if settings.USE_TZ and value is not None:
|
||||||
if value is not None:
|
tz = timezone.get_current_timezone()
|
||||||
tz = timezone.get_current_timezone()
|
value = datetime(value.year, value.month, value.day)
|
||||||
value = datetime(value.year, value.month, value.day)
|
value = make_aware(value, tz, True)
|
||||||
value = make_aware(value, tz, True)
|
|
||||||
|
|
||||||
return super().filter(qs, value)
|
return super().filter(qs, value)
|
||||||
|
|
||||||
|
@ -69,7 +69,7 @@ def construct_format_regex(fmt_string: str) -> str:
|
|||||||
for group in string.Formatter().parse(fmt_string):
|
for group in string.Formatter().parse(fmt_string):
|
||||||
prefix = group[0] # Prefix (literal text appearing before this group)
|
prefix = group[0] # Prefix (literal text appearing before this group)
|
||||||
name = group[1] # Name of this format variable
|
name = group[1] # Name of this format variable
|
||||||
format = group[2] # Format specifier e.g :04d
|
_fmt = group[2] # Format specifier e.g :04d
|
||||||
|
|
||||||
rep = [
|
rep = [
|
||||||
'+',
|
'+',
|
||||||
@ -106,16 +106,16 @@ def construct_format_regex(fmt_string: str) -> str:
|
|||||||
# Add a named capture group for the format entry
|
# Add a named capture group for the format entry
|
||||||
if name:
|
if name:
|
||||||
# Check if integer values are required
|
# Check if integer values are required
|
||||||
if format.endswith('d'):
|
if _fmt.endswith('d'):
|
||||||
chr = '\d'
|
c = '\d'
|
||||||
else:
|
else:
|
||||||
chr = '.'
|
c = '.'
|
||||||
|
|
||||||
# Specify width
|
# Specify width
|
||||||
# TODO: Introspect required width
|
# TODO: Introspect required width
|
||||||
w = '+'
|
w = '+'
|
||||||
|
|
||||||
pattern += f'(?P<{name}>{chr}{w})'
|
pattern += f'(?P<{name}>{c}{w})'
|
||||||
|
|
||||||
pattern += '$'
|
pattern += '$'
|
||||||
|
|
||||||
|
@ -248,11 +248,7 @@ def str2int(text, default=None):
|
|||||||
|
|
||||||
def is_bool(text):
|
def is_bool(text):
|
||||||
"""Determine if a string value 'looks' like a boolean."""
|
"""Determine if a string value 'looks' like a boolean."""
|
||||||
if str2bool(text, True):
|
return str2bool(text, True) or str2bool(text, False)
|
||||||
return True
|
|
||||||
elif str2bool(text, False):
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def isNull(text):
|
def isNull(text):
|
||||||
@ -473,7 +469,7 @@ def DownloadFile(
|
|||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
def increment_serial_number(serial: str):
|
def increment_serial_number(serial):
|
||||||
"""Given a serial number, (attempt to) generate the *next* serial number.
|
"""Given a serial number, (attempt to) generate the *next* serial number.
|
||||||
|
|
||||||
Note: This method is exposed to custom plugins.
|
Note: This method is exposed to custom plugins.
|
||||||
@ -857,9 +853,9 @@ def hash_barcode(barcode_data):
|
|||||||
barcode_data = str(barcode_data).strip()
|
barcode_data = str(barcode_data).strip()
|
||||||
barcode_data = remove_non_printable_characters(barcode_data)
|
barcode_data = remove_non_printable_characters(barcode_data)
|
||||||
|
|
||||||
hash = hashlib.md5(str(barcode_data).encode())
|
barcode_hash = hashlib.md5(str(barcode_data).encode())
|
||||||
|
|
||||||
return str(hash.hexdigest())
|
return str(barcode_hash.hexdigest())
|
||||||
|
|
||||||
|
|
||||||
def hash_file(filename: Union[str, Path], storage: Union[Storage, None] = None):
|
def hash_file(filename: Union[str, Path], storage: Union[Storage, None] = None):
|
||||||
|
@ -7,7 +7,7 @@ from rest_framework import permissions
|
|||||||
import users.models
|
import users.models
|
||||||
|
|
||||||
|
|
||||||
def get_model_for_view(view, raise_error=True):
|
def get_model_for_view(view):
|
||||||
"""Attempt to introspect the 'model' type for an API view."""
|
"""Attempt to introspect the 'model' type for an API view."""
|
||||||
if hasattr(view, 'get_permission_model'):
|
if hasattr(view, 'get_permission_model'):
|
||||||
return view.get_permission_model()
|
return view.get_permission_model()
|
||||||
|
@ -85,7 +85,7 @@ for name, provider in providers.registry.provider_map.items():
|
|||||||
cls
|
cls
|
||||||
for cls in prov_mod.__dict__.values()
|
for cls in prov_mod.__dict__.values()
|
||||||
if isinstance(cls, type)
|
if isinstance(cls, type)
|
||||||
and not cls == OAuth2Adapter
|
and cls != OAuth2Adapter
|
||||||
and issubclass(cls, OAuth2Adapter)
|
and issubclass(cls, OAuth2Adapter)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -27,7 +27,7 @@ def get_provider_app(provider):
|
|||||||
return apps.first()
|
return apps.first()
|
||||||
|
|
||||||
|
|
||||||
def check_provider(provider, raise_error=False):
|
def check_provider(provider):
|
||||||
"""Check if the given provider is correctly configured.
|
"""Check if the given provider is correctly configured.
|
||||||
|
|
||||||
To be correctly configured, the following must be true:
|
To be correctly configured, the following must be true:
|
||||||
|
Loading…
Reference in New Issue
Block a user