chore: apply pyupgrade --py38-plus

This commit is contained in:
Éloi Rivard 2023-07-27 17:04:39 +02:00
parent d057cdbf35
commit c8b983d5b4
No known key found for this signature in database
GPG key ID: 7EDA204EA57DD184
10 changed files with 21 additions and 27 deletions

View file

@ -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):

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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 "<Transaction %s>" % ", ".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

View file

@ -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"),
)

View file

@ -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"<td class=\"balance-name\">{}</td>".format(name) for name in order
)
regex2 = r".*".join(
r"<td class=\"d-md-none\">{}</td>".format(name) for name in order
rf"<td class=\"balance-name\">{name}</td>" for name in order
)
regex2 = r".*".join(rf"<td class=\"d-md-none\">{name}</td>" 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))

View file

@ -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()

View file

@ -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