diff --git a/ihatemoney/api/common.py b/ihatemoney/api/common.py index caf8148b..4068b63c 100644 --- a/ihatemoney/api/common.py +++ b/ihatemoney/api/common.py @@ -107,7 +107,7 @@ class APIMemberForm(MemberForm): def save(self, project, person): person.activated = self.activated.data - return super(APIMemberForm, self).save(project, person) + return super().save(project, person) class MembersHandler(Resource): diff --git a/ihatemoney/currency_convertor.py b/ihatemoney/currency_convertor.py index 1139a445..45710dd5 100644 --- a/ihatemoney/currency_convertor.py +++ b/ihatemoney/currency_convertor.py @@ -10,11 +10,11 @@ class Singleton(type): def __call__(cls, *args, **kwargs): if cls not in cls._instances: - cls._instances[cls] = super(Singleton, cls).__call__(*args, **kwargs) + cls._instances[cls] = super().__call__(*args, **kwargs) return cls._instances[cls] -class CurrencyConverter(object, metaclass=Singleton): +class CurrencyConverter(metaclass=Singleton): # Get exchange rates no_currency = "XXX" api_url = "https://api.exchangerate.host/latest?base=USD" diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index 1bfb0fe2..404a8382 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -92,7 +92,7 @@ class CommaDecimalField(DecimalField): def process_formdata(self, value): if value: value[0] = str(value[0]).replace(",", ".") - return super(CommaDecimalField, self).process_formdata(value) + return super().process_formdata(value) class CalculatorStringField(StringField): @@ -116,7 +116,7 @@ class CalculatorStringField(StringField): valuelist[0] = str(eval_arithmetic_expression(value)) - return super(CalculatorStringField, self).process_formdata(valuelist) + return super().process_formdata(valuelist) class EditProjectForm(FlaskForm): @@ -400,7 +400,7 @@ class MemberForm(FlaskForm): submit = SubmitField(_("Add")) def __init__(self, project, edit=False, *args, **kwargs): - super(MemberForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.project = project self.edit = edit diff --git a/ihatemoney/migrations/env.py b/ihatemoney/migrations/env.py index 1a443181..7036db89 100755 --- a/ihatemoney/migrations/env.py +++ b/ihatemoney/migrations/env.py @@ -1,4 +1,3 @@ -from __future__ import with_statement from alembic import context from sqlalchemy import engine_from_config, pool from logging.config import fileConfig diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 80732529..7c147dfd 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -229,7 +229,7 @@ class Project(db.Model): # but this is called very rarely so we can tolerate if it's a bit # slow. And doing this in Python is much more readable, see #784. nb_currencies = len( - set(bill.original_currency for bill in self.get_bills_unordered()) + {bill.original_currency for bill in self.get_bills_unordered()} ) return nb_currencies > 1 diff --git a/ihatemoney/monkeypath_continuum.py b/ihatemoney/monkeypath_continuum.py index a52c92fa..3c79e3a1 100644 --- a/ihatemoney/monkeypath_continuum.py +++ b/ihatemoney/monkeypath_continuum.py @@ -1,6 +1,5 @@ from collections import OrderedDict -import six import sqlalchemy as sa from sqlalchemy_continuum import __version__ as continuum_version from sqlalchemy_continuum.exc import ImproperlyConfigured @@ -53,7 +52,7 @@ class PatchedTransactionFactory(TransactionFactory): except AttributeError: # SQLAlchemy < 1.4 registry = Base._decl_class_registry - if isinstance(user_cls, six.string_types): + if isinstance(user_cls, str): try: user_cls = registry[user_cls] except KeyError: @@ -82,8 +81,7 @@ class PatchedTransactionFactory(TransactionFactory): ) return "" % ", ".join( ( - "%s=%r" % (field, value) - if not isinstance(value, six.integer_types) + f"{field}={value!r}" if not isinstance(value, int) # We want the following line to ensure that longs get # shown without the ugly L suffix on python 2.x # versions diff --git a/ihatemoney/tests/api_test.py b/ihatemoney/tests/api_test.py index 21c61e17..e3964940 100644 --- a/ihatemoney/tests/api_test.py +++ b/ihatemoney/tests/api_test.py @@ -42,7 +42,7 @@ class APITestCase(IhatemoneyTestCase): def get_auth(self, username, password=None): password = password or username base64string = ( - base64.encodebytes(f"{username}:{password}".encode("utf-8")) + base64.encodebytes(f"{username}:{password}".encode()) .decode("utf-8") .replace("\n", "") ) @@ -518,11 +518,11 @@ class APITestCase(IhatemoneyTestCase): # should return the id self.assertStatus(201, req) - self.assertEqual(req.data.decode("utf-8"), "{}\n".format(id)) + self.assertEqual(req.data.decode("utf-8"), f"{id}\n") # get this bill's details req = self.client.get( - "/api/projects/raclette/bills/{}".format(id), + f"/api/projects/raclette/bills/{id}", headers=self.get_auth("raclette"), ) diff --git a/ihatemoney/tests/budget_test.py b/ihatemoney/tests/budget_test.py index 6110fabd..7c700803 100644 --- a/ihatemoney/tests/budget_test.py +++ b/ihatemoney/tests/budget_test.py @@ -708,7 +708,7 @@ class BudgetTestCase(IhatemoneyTestCase): ) balance = self.get_project("raclette").balance - self.assertEqual(set(balance.values()), set([19.0, -19.0])) + self.assertEqual(set(balance.values()), {19.0, -19.0}) # Bill with negative amount self.client.post( @@ -802,7 +802,7 @@ class BudgetTestCase(IhatemoneyTestCase): ) balance = self.get_project("raclette").balance - self.assertEqual(set(balance.values()), set([6, -6])) + self.assertEqual(set(balance.values()), {6, -6}) def test_trimmed_members(self): self.post_project("raclette") @@ -1044,11 +1044,9 @@ class BudgetTestCase(IhatemoneyTestCase): # same as in the main table. order = ["fred", "pépé", "tata", "zorglub"] regex1 = r".*".join( - r"{}".format(name) for name in order - ) - regex2 = r".*".join( - r"{}".format(name) for name in order + rf"{name}" for name in order ) + regex2 = r".*".join(rf"{name}" for name in order) # Build the regexp ourselves to be able to pass the DOTALL flag # (so that ".*" matches newlines) self.assertRegex(response.data.decode("utf-8"), re.compile(regex1, re.DOTALL)) diff --git a/ihatemoney/tests/import_test.py b/ihatemoney/tests/import_test.py index bccb254d..b65de783 100644 --- a/ihatemoney/tests/import_test.py +++ b/ihatemoney/tests/import_test.py @@ -6,7 +6,7 @@ from ihatemoney.tests.common.ihatemoney_testcase import IhatemoneyTestCase from ihatemoney.utils import list_of_dicts2csv, list_of_dicts2json -class CommonTestCase(object): +class CommonTestCase: class Import(IhatemoneyTestCase): def setUp(self): super().setUp() diff --git a/ihatemoney/utils.py b/ihatemoney/utils.py index 554d0eec..3b7de675 100644 --- a/ihatemoney/utils.py +++ b/ihatemoney/utils.py @@ -8,7 +8,6 @@ import operator import os import re import smtplib -import socket from babel import Locale from babel.numbers import get_currency_name, get_currency_symbol @@ -50,7 +49,7 @@ def send_email(mail_message): # to check for both. try: current_app.mail.send(mail_message) - except (smtplib.SMTPException, socket.error): + except (smtplib.SMTPException, OSError): return False # Email was sent successfully return True @@ -100,7 +99,7 @@ class Redirect303(HTTPException, RoutingException): return redirect(self.new_url, 303) -class PrefixedWSGI(object): +class PrefixedWSGI: """ Wrap the application in this middleware and configure the @@ -148,7 +147,7 @@ def minimal_round(*args, **kw): def static_include(filename): fullpath = os.path.join(current_app.static_folder, filename) - with open(fullpath, "r") as f: + with open(fullpath) as f: return f.read() @@ -284,7 +283,7 @@ def eval_arithmetic_expression(expr): try: result = _eval(ast.parse(expr, mode="eval").body) except (SyntaxError, TypeError, ZeroDivisionError, KeyError): - raise ValueError("Error evaluating expression: {}".format(expr)) + raise ValueError(f"Error evaluating expression: {expr}") return result