* bump deps

* use isinstance where possible

* and another bump ;-)

* small fix for isinstance

* fixed wrong comparison

* fixed comparision

* use exact comparision
This commit is contained in:
Matthias Mair 2023-08-06 13:39:15 +02:00 committed by GitHub
parent 54e0e47c6a
commit 879d496e26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 31 additions and 31 deletions

View File

@ -45,7 +45,7 @@ def to_dict(value):
if value is None: if value is None:
return {} return {}
if type(value) == dict: if isinstance(value, dict):
return value return value
try: try:

View File

@ -53,7 +53,7 @@ def is_email_configured():
def send_email(subject, body, recipients, from_email=None, html_message=None): def send_email(subject, body, recipients, from_email=None, html_message=None):
"""Send an email with the specified subject and body, to the specified recipients list.""" """Send an email with the specified subject and body, to the specified recipients list."""
if type(recipients) == str: if isinstance(recipients, str):
recipients = [recipients] recipients = [recipients]
import InvenTree.ready import InvenTree.ready

View File

@ -387,13 +387,13 @@ def DownloadFile(data, filename, content_type='application/text', inline=False)
filename = WrapWithQuotes(filename) filename = WrapWithQuotes(filename)
length = len(data) length = len(data)
if type(data) == str: if isinstance(data, str):
wrapper = FileWrapper(io.StringIO(data)) wrapper = FileWrapper(io.StringIO(data))
else: else:
wrapper = FileWrapper(io.BytesIO(data)) wrapper = FileWrapper(io.BytesIO(data))
response = StreamingHttpResponse(wrapper, content_type=content_type) response = StreamingHttpResponse(wrapper, content_type=content_type)
if type(data) == str: if isinstance(data, str):
length = len(bytes(data, response.charset)) length = len(bytes(data, response.charset))
response['Content-Length'] = length response['Content-Length'] = length

View File

@ -57,7 +57,7 @@ def sanitize_svg(file_data, strip: bool = True, elements: str = ALLOWED_ELEMENTS
""" """
# Handle byte-encoded data # Handle byte-encoded data
if type(file_data) == bytes: if isinstance(file_data, bytes):
file_data = file_data.decode('utf-8') file_data = file_data.decode('utf-8')
cleaned = clean( cleaned = clean(

View File

@ -17,13 +17,13 @@ class BaseEnum(enum.IntEnum):
def __eq__(self, obj): def __eq__(self, obj):
"""Override equality operator to allow comparison with int.""" """Override equality operator to allow comparison with int."""
if type(self) == type(obj): if type(self) is type(obj):
return super().__eq__(obj) return super().__eq__(obj)
return self.value == obj return self.value == obj
def __ne__(self, obj): def __ne__(self, obj):
"""Override inequality operator to allow comparison with int.""" """Override inequality operator to allow comparison with int."""
if type(self) == type(obj): if type(self) is type(obj):
return super().__ne__(obj) return super().__ne__(obj)
return self.value != obj return self.value != obj
@ -70,7 +70,7 @@ class StatusCode(BaseEnum):
return False return False
if callable(value): if callable(value):
return False return False
if type(value.value) != int: if not isinstance(value.value, int):
return False return False
return True return True

View File

@ -1878,7 +1878,7 @@ class BomItemValidate(UpdateAPI):
serializer = self.get_serializer(instance, data=data, partial=partial) serializer = self.get_serializer(instance, data=data, partial=partial)
serializer.is_valid(raise_exception=True) serializer.is_valid(raise_exception=True)
if type(instance) == BomItem: if isinstance(instance, BomItem):
instance.validate_hash(valid) instance.validate_hash(valid)
return Response(serializer.data) return Response(serializer.data)

View File

@ -55,7 +55,7 @@ def render_date(context, date_object):
if date_object is None: if date_object is None:
return None return None
if type(date_object) == str: if isinstance(date_object, str):
date_object = date_object.strip() date_object = date_object.strip()

View File

@ -377,7 +377,7 @@ class BuildReport(ReportTemplateBase):
"""Custom context data for the build report.""" """Custom context data for the build report."""
my_build = self.object_to_print my_build = self.object_to_print
if type(my_build) != build.models.Build: if not isinstance(my_build, build.models.Build):
raise TypeError('Provided model is not a Build object') raise TypeError('Provided model is not a Build object')
return { return {
@ -653,7 +653,7 @@ class StockLocationReport(ReportTemplateBase):
"""Return custom context data for the StockLocationReport template""" """Return custom context data for the StockLocationReport template"""
stock_location = self.object_to_print stock_location = self.object_to_print
if type(stock_location) != stock.models.StockLocation: if not isinstance(stock_location, stock.models.StockLocation):
raise TypeError('Provided model is not a StockLocation object -> ' + str(type(stock_location))) raise TypeError('Provided model is not a StockLocation object -> ' + str(type(stock_location)))
return { return {

View File

@ -168,12 +168,12 @@ class BarcodeTagTest(TestCase):
barcode = barcode_tags.barcode("12345") barcode = barcode_tags.barcode("12345")
self.assertTrue(type(barcode) == str) self.assertTrue(isinstance(barcode, str))
self.assertTrue(barcode.startswith('data:image/png;')) self.assertTrue(barcode.startswith('data:image/png;'))
# Try with a different format # Try with a different format
barcode = barcode_tags.barcode('99999', format='BMP') barcode = barcode_tags.barcode('99999', format='BMP')
self.assertTrue(type(barcode) == str) self.assertTrue(isinstance(barcode, str))
self.assertTrue(barcode.startswith('data:image/bmp;')) self.assertTrue(barcode.startswith('data:image/bmp;'))
def test_qrcode(self): def test_qrcode(self):
@ -181,7 +181,7 @@ class BarcodeTagTest(TestCase):
# Test with default settings # Test with default settings
qrcode = barcode_tags.qrcode("hello world") qrcode = barcode_tags.qrcode("hello world")
self.assertTrue(type(qrcode) == str) self.assertTrue(isinstance(qrcode, str))
self.assertTrue(qrcode.startswith('data:image/png;')) self.assertTrue(qrcode.startswith('data:image/png;'))
self.assertEqual(len(qrcode), 700) self.assertEqual(len(qrcode), 700)
@ -192,7 +192,7 @@ class BarcodeTagTest(TestCase):
box_size=50, box_size=50,
format='BMP', format='BMP',
) )
self.assertTrue(type(qrcode) == str) self.assertTrue(isinstance(qrcode, str))
self.assertTrue(qrcode.startswith('data:image/bmp;')) self.assertTrue(qrcode.startswith('data:image/bmp;'))
self.assertEqual(len(qrcode), 309720) self.assertEqual(len(qrcode), 309720)

View File

@ -45,7 +45,7 @@ docopt==0.6.2
# via coveralls # via coveralls
filelock==3.12.2 filelock==3.12.2
# via virtualenv # via virtualenv
flake8==6.0.0 flake8==6.1.0
# via # via
# -r requirements-dev.in # -r requirements-dev.in
# flake8-docstrings # flake8-docstrings
@ -70,17 +70,17 @@ packaging==23.1
# build # build
pep8-naming==0.13.3 pep8-naming==0.13.3
# via -r requirements-dev.in # via -r requirements-dev.in
pip-tools==7.1.0 pip-tools==7.2.0
# via -r requirements-dev.in # via -r requirements-dev.in
platformdirs==3.9.1 platformdirs==3.10.0
# via virtualenv # via virtualenv
pre-commit==3.3.3 pre-commit==3.3.3
# via -r requirements-dev.in # via -r requirements-dev.in
pycodestyle==2.10.0 pycodestyle==2.11.0
# via flake8 # via flake8
pydocstyle==6.3.0 pydocstyle==6.3.0
# via flake8-docstrings # via flake8-docstrings
pyflakes==3.0.1 pyflakes==3.1.0
# via flake8 # via flake8
pyproject-hooks==1.0.0 pyproject-hooks==1.0.0
# via build # via build
@ -117,9 +117,9 @@ urllib3==2.0.4
# via # via
# -c requirements.txt # -c requirements.txt
# requests # requests
virtualenv==20.24.1 virtualenv==20.24.2
# via pre-commit # via pre-commit
wheel==0.41.0 wheel==0.41.1
# via pip-tools # via pip-tools
# The following packages are considered to be unsafe in a requirements file: # The following packages are considered to be unsafe in a requirements file:

View File

@ -32,7 +32,7 @@ coreapi==2.3.3
# via -r requirements.in # via -r requirements.in
coreschema==0.0.4 coreschema==0.0.4
# via coreapi # via coreapi
cryptography==41.0.2 cryptography==41.0.3
# via # via
# -r requirements.in # -r requirements.in
# djangorestframework-simplejwt # djangorestframework-simplejwt
@ -129,7 +129,7 @@ django-recurrence==1.11.1
# via django-ical # via django-ical
django-redis==5.3.0 django-redis==5.3.0
# via -r requirements.in # via -r requirements.in
django-sesame==3.1 django-sesame==3.2
# via -r requirements.in # via -r requirements.in
django-sql-utils==0.6.1 django-sql-utils==0.6.1
# via -r requirements.in # via -r requirements.in
@ -153,7 +153,7 @@ djangorestframework==3.14.0
# drf-spectacular # drf-spectacular
djangorestframework-simplejwt[crypto]==5.2.2 djangorestframework-simplejwt[crypto]==5.2.2
# via -r requirements.in # via -r requirements.in
drf-spectacular==0.26.3 drf-spectacular==0.26.4
# via -r requirements.in # via -r requirements.in
dulwich==0.21.5 dulwich==0.21.5
# via -r requirements.in # via -r requirements.in
@ -161,7 +161,7 @@ et-xmlfile==1.1.0
# via openpyxl # via openpyxl
feedparser==6.0.10 feedparser==6.0.10
# via -r requirements.in # via -r requirements.in
fonttools[woff]==4.41.1 fonttools[woff]==4.42.0
# via weasyprint # via weasyprint
gunicorn==21.2.0 gunicorn==21.2.0
# via -r requirements.in # via -r requirements.in
@ -179,11 +179,11 @@ itypes==1.2.0
# via coreapi # via coreapi
jinja2==3.1.2 jinja2==3.1.2
# via coreschema # via coreschema
jsonschema==4.18.4 jsonschema==4.18.6
# via drf-spectacular # via drf-spectacular
jsonschema-specifications==2023.7.1 jsonschema-specifications==2023.7.1
# via jsonschema # via jsonschema
markdown==3.4.3 markdown==3.4.4
# via django-markdownify # via django-markdownify
markuppy==1.14 markuppy==1.14
# via tablib # via tablib
@ -256,7 +256,7 @@ rapidfuzz==0.7.6
# via -r requirements.in # via -r requirements.in
redis==4.6.0 redis==4.6.0
# via django-redis # via django-redis
referencing==0.30.0 referencing==0.30.2
# via # via
# jsonschema # jsonschema
# jsonschema-specifications # jsonschema-specifications
@ -273,7 +273,7 @@ rpds-py==0.9.2
# via # via
# jsonschema # jsonschema
# referencing # referencing
sentry-sdk==1.28.1 sentry-sdk==1.29.2
# via # via
# -r requirements.in # -r requirements.in
# django-q-sentry # django-q-sentry