From 78e9de2179b52cf2047db42787c5d74f1b163ca9 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Tue, 20 Aug 2024 00:41:06 +0200 Subject: [PATCH] fix a number of A002 cases --- docs/main.py | 7 ++++--- pyproject.toml | 2 +- src/backend/InvenTree/InvenTree/format.py | 8 ++++---- src/backend/InvenTree/InvenTree/views.py | 4 ++-- src/backend/InvenTree/common/api.py | 4 ++-- .../InvenTree/report/templatetags/report.py | 16 ++++++++-------- 6 files changed, 21 insertions(+), 20 deletions(-) diff --git a/docs/main.py b/docs/main.py index 2a92311ecd..84b91f7ad8 100644 --- a/docs/main.py +++ b/docs/main.py @@ -200,12 +200,13 @@ def define_env(env): return assets @env.macro - def includefile(filename: str, title: str, format: str = ''): + def includefile(filename: str, title: str, fmt: str = ''): """Include a file in the documentation, in a 'collapse' block. Arguments: - filename: The name of the file to include (relative to the top-level directory) - title: + - fmt: """ here = os.path.dirname(__file__) path = os.path.join(here, '..', filename) @@ -218,7 +219,7 @@ def define_env(env): content = f.read() data = f'??? abstract "{title}"\n\n' - data += f' ```{format}\n' + data += f' ```{fmt}\n' data += textwrap.indent(content, ' ') data += '\n\n' data += ' ```\n\n' @@ -233,7 +234,7 @@ def define_env(env): 'src', 'backend', 'InvenTree', 'report', 'templates', filename ) - return includefile(fn, f'Template: {base}', format='html') + return includefile(fn, f'Template: {base}', fmt='html') @env.macro def rendersetting(setting: dict): diff --git a/pyproject.toml b/pyproject.toml index 5a34584525..bfd09bdb7e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,7 +59,7 @@ ignore = [ "B904", # Remove fast - "A001", "A002","A003","B018" + "A001", "A002", "B018" ] [tool.ruff.lint.pydocstyle] diff --git a/src/backend/InvenTree/InvenTree/format.py b/src/backend/InvenTree/InvenTree/format.py index 7d959f5596..4d92722167 100644 --- a/src/backend/InvenTree/InvenTree/format.py +++ b/src/backend/InvenTree/InvenTree/format.py @@ -181,7 +181,7 @@ def extract_named_group(name: str, value: str, fmt_string: str) -> str: def format_money( money: Money, decimal_places: Optional[int] = None, - format: Optional[str] = None, + fmt: Optional[str] = None, include_symbol: bool = True, ) -> str: """Format money object according to the currently set local. @@ -189,7 +189,7 @@ def format_money( Args: money (Money): The money object to format decimal_places (int): Number of decimal places to use - format (str): Format pattern according LDML / the babel format pattern syntax (https://babel.pocoo.org/en/latest/numbers.html) + fmt (str): Format pattern according LDML / the babel format pattern syntax (https://babel.pocoo.org/en/latest/numbers.html) Returns: str: The formatted string @@ -199,8 +199,8 @@ def format_money( """ language = (None) or settings.LANGUAGE_CODE locale = Locale.parse(translation.to_locale(language)) - if format: - pattern = parse_pattern(format) + if fmt: + pattern = parse_pattern(fmt) else: pattern = locale.currency_formats['standard'] if decimal_places is not None: diff --git a/src/backend/InvenTree/InvenTree/views.py b/src/backend/InvenTree/InvenTree/views.py index a12705666a..b53990be20 100644 --- a/src/backend/InvenTree/InvenTree/views.py +++ b/src/backend/InvenTree/InvenTree/views.py @@ -328,11 +328,11 @@ class AjaxUpdateView(AjaxMixin, UpdateView): request, self.get_form(), context=self.get_context_data() ) - def save(self, object, form, **kwargs): + def save(self, obj, form, **kwargs): """Method for updating the object in the database. Default implementation is very simple, but can be overridden if required. Args: - object: The current object, to be updated + obj: The current object, to be updated form: The validated form Returns: diff --git a/src/backend/InvenTree/common/api.py b/src/backend/InvenTree/common/api.py index 75f0a1c77a..db9f6ce75d 100644 --- a/src/backend/InvenTree/common/api.py +++ b/src/backend/InvenTree/common/api.py @@ -136,7 +136,7 @@ class CurrencyExchangeView(APIView): serializer_class = None @extend_schema(responses={200: common.serializers.CurrencyExchangeSerializer}) - def get(self, request, format=None): + def get(self, request, fmt=None): """Return information on available currency conversions.""" # Extract a list of all available rates try: @@ -563,7 +563,7 @@ class BackgroundTaskOverview(APIView): permission_classes = [permissions.IsAuthenticated, IsAdminUser] serializer_class = None - def get(self, request, format=None): + def get(self, request, fmt=None): """Return information about the current status of the background task queue.""" import django_q.models as q_models diff --git a/src/backend/InvenTree/report/templatetags/report.py b/src/backend/InvenTree/report/templatetags/report.py index ed3c659323..6af0fff5cc 100644 --- a/src/backend/InvenTree/report/templatetags/report.py +++ b/src/backend/InvenTree/report/templatetags/report.py @@ -444,35 +444,35 @@ def format_number(number, **kwargs): @register.simple_tag -def format_datetime(datetime, timezone=None, format=None): +def format_datetime(datetime, timezone=None, fmt=None): """Format a datetime object for display. Arguments: datetime: The datetime object to format timezone: The timezone to use for the date (defaults to the server timezone) - format: The format string to use (defaults to ISO formatting) + fmt: The format string to use (defaults to ISO formatting) """ datetime = InvenTree.helpers.to_local_time(datetime, timezone) - if format: - return datetime.strftime(format) + if fmt: + return datetime.strftime(fmt) else: return datetime.isoformat() @register.simple_tag -def format_date(date, timezone=None, format=None): +def format_date(date, timezone=None, fmt=None): """Format a date object for display. Arguments: date: The date to format timezone: The timezone to use for the date (defaults to the server timezone) - format: The format string to use (defaults to ISO formatting) + fmt: The format string to use (defaults to ISO formatting) """ date = InvenTree.helpers.to_local_time(date, timezone).date() - if format: - return date.strftime(format) + if fmt: + return date.strftime(fmt) else: return date.isoformat()