mirror of
https://github.com/spiral-project/ihatemoney.git
synced 2025-04-28 17:32:38 +02:00
chore: apply pyupgrade --py38-plus
This commit is contained in:
parent
d057cdbf35
commit
c8b983d5b4
10 changed files with 21 additions and 27 deletions
|
@ -107,7 +107,7 @@ class APIMemberForm(MemberForm):
|
||||||
|
|
||||||
def save(self, project, person):
|
def save(self, project, person):
|
||||||
person.activated = self.activated.data
|
person.activated = self.activated.data
|
||||||
return super(APIMemberForm, self).save(project, person)
|
return super().save(project, person)
|
||||||
|
|
||||||
|
|
||||||
class MembersHandler(Resource):
|
class MembersHandler(Resource):
|
||||||
|
|
|
@ -10,11 +10,11 @@ class Singleton(type):
|
||||||
|
|
||||||
def __call__(cls, *args, **kwargs):
|
def __call__(cls, *args, **kwargs):
|
||||||
if cls not in cls._instances:
|
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]
|
return cls._instances[cls]
|
||||||
|
|
||||||
|
|
||||||
class CurrencyConverter(object, metaclass=Singleton):
|
class CurrencyConverter(metaclass=Singleton):
|
||||||
# Get exchange rates
|
# Get exchange rates
|
||||||
no_currency = "XXX"
|
no_currency = "XXX"
|
||||||
api_url = "https://api.exchangerate.host/latest?base=USD"
|
api_url = "https://api.exchangerate.host/latest?base=USD"
|
||||||
|
|
|
@ -92,7 +92,7 @@ class CommaDecimalField(DecimalField):
|
||||||
def process_formdata(self, value):
|
def process_formdata(self, value):
|
||||||
if value:
|
if value:
|
||||||
value[0] = str(value[0]).replace(",", ".")
|
value[0] = str(value[0]).replace(",", ".")
|
||||||
return super(CommaDecimalField, self).process_formdata(value)
|
return super().process_formdata(value)
|
||||||
|
|
||||||
|
|
||||||
class CalculatorStringField(StringField):
|
class CalculatorStringField(StringField):
|
||||||
|
@ -116,7 +116,7 @@ class CalculatorStringField(StringField):
|
||||||
|
|
||||||
valuelist[0] = str(eval_arithmetic_expression(value))
|
valuelist[0] = str(eval_arithmetic_expression(value))
|
||||||
|
|
||||||
return super(CalculatorStringField, self).process_formdata(valuelist)
|
return super().process_formdata(valuelist)
|
||||||
|
|
||||||
|
|
||||||
class EditProjectForm(FlaskForm):
|
class EditProjectForm(FlaskForm):
|
||||||
|
@ -400,7 +400,7 @@ class MemberForm(FlaskForm):
|
||||||
submit = SubmitField(_("Add"))
|
submit = SubmitField(_("Add"))
|
||||||
|
|
||||||
def __init__(self, project, edit=False, *args, **kwargs):
|
def __init__(self, project, edit=False, *args, **kwargs):
|
||||||
super(MemberForm, self).__init__(*args, **kwargs)
|
super().__init__(*args, **kwargs)
|
||||||
self.project = project
|
self.project = project
|
||||||
self.edit = edit
|
self.edit = edit
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
from __future__ import with_statement
|
|
||||||
from alembic import context
|
from alembic import context
|
||||||
from sqlalchemy import engine_from_config, pool
|
from sqlalchemy import engine_from_config, pool
|
||||||
from logging.config import fileConfig
|
from logging.config import fileConfig
|
||||||
|
|
|
@ -229,7 +229,7 @@ class Project(db.Model):
|
||||||
# but this is called very rarely so we can tolerate if it's a bit
|
# 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.
|
# slow. And doing this in Python is much more readable, see #784.
|
||||||
nb_currencies = len(
|
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
|
return nb_currencies > 1
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
import six
|
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy_continuum import __version__ as continuum_version
|
from sqlalchemy_continuum import __version__ as continuum_version
|
||||||
from sqlalchemy_continuum.exc import ImproperlyConfigured
|
from sqlalchemy_continuum.exc import ImproperlyConfigured
|
||||||
|
@ -53,7 +52,7 @@ class PatchedTransactionFactory(TransactionFactory):
|
||||||
except AttributeError: # SQLAlchemy < 1.4
|
except AttributeError: # SQLAlchemy < 1.4
|
||||||
registry = Base._decl_class_registry
|
registry = Base._decl_class_registry
|
||||||
|
|
||||||
if isinstance(user_cls, six.string_types):
|
if isinstance(user_cls, str):
|
||||||
try:
|
try:
|
||||||
user_cls = registry[user_cls]
|
user_cls = registry[user_cls]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -82,8 +81,7 @@ class PatchedTransactionFactory(TransactionFactory):
|
||||||
)
|
)
|
||||||
return "<Transaction %s>" % ", ".join(
|
return "<Transaction %s>" % ", ".join(
|
||||||
(
|
(
|
||||||
"%s=%r" % (field, value)
|
f"{field}={value!r}" if not isinstance(value, int)
|
||||||
if not isinstance(value, six.integer_types)
|
|
||||||
# We want the following line to ensure that longs get
|
# We want the following line to ensure that longs get
|
||||||
# shown without the ugly L suffix on python 2.x
|
# shown without the ugly L suffix on python 2.x
|
||||||
# versions
|
# versions
|
||||||
|
|
|
@ -42,7 +42,7 @@ class APITestCase(IhatemoneyTestCase):
|
||||||
def get_auth(self, username, password=None):
|
def get_auth(self, username, password=None):
|
||||||
password = password or username
|
password = password or username
|
||||||
base64string = (
|
base64string = (
|
||||||
base64.encodebytes(f"{username}:{password}".encode("utf-8"))
|
base64.encodebytes(f"{username}:{password}".encode())
|
||||||
.decode("utf-8")
|
.decode("utf-8")
|
||||||
.replace("\n", "")
|
.replace("\n", "")
|
||||||
)
|
)
|
||||||
|
@ -518,11 +518,11 @@ class APITestCase(IhatemoneyTestCase):
|
||||||
|
|
||||||
# should return the id
|
# should return the id
|
||||||
self.assertStatus(201, req)
|
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
|
# get this bill's details
|
||||||
req = self.client.get(
|
req = self.client.get(
|
||||||
"/api/projects/raclette/bills/{}".format(id),
|
f"/api/projects/raclette/bills/{id}",
|
||||||
headers=self.get_auth("raclette"),
|
headers=self.get_auth("raclette"),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -708,7 +708,7 @@ class BudgetTestCase(IhatemoneyTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
balance = self.get_project("raclette").balance
|
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
|
# Bill with negative amount
|
||||||
self.client.post(
|
self.client.post(
|
||||||
|
@ -802,7 +802,7 @@ class BudgetTestCase(IhatemoneyTestCase):
|
||||||
)
|
)
|
||||||
|
|
||||||
balance = self.get_project("raclette").balance
|
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):
|
def test_trimmed_members(self):
|
||||||
self.post_project("raclette")
|
self.post_project("raclette")
|
||||||
|
@ -1044,11 +1044,9 @@ class BudgetTestCase(IhatemoneyTestCase):
|
||||||
# same as in the main table.
|
# same as in the main table.
|
||||||
order = ["fred", "pépé", "tata", "zorglub"]
|
order = ["fred", "pépé", "tata", "zorglub"]
|
||||||
regex1 = r".*".join(
|
regex1 = r".*".join(
|
||||||
r"<td class=\"balance-name\">{}</td>".format(name) for name in order
|
rf"<td class=\"balance-name\">{name}</td>" for name in order
|
||||||
)
|
|
||||||
regex2 = r".*".join(
|
|
||||||
r"<td class=\"d-md-none\">{}</td>".format(name) 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
|
# Build the regexp ourselves to be able to pass the DOTALL flag
|
||||||
# (so that ".*" matches newlines)
|
# (so that ".*" matches newlines)
|
||||||
self.assertRegex(response.data.decode("utf-8"), re.compile(regex1, re.DOTALL))
|
self.assertRegex(response.data.decode("utf-8"), re.compile(regex1, re.DOTALL))
|
||||||
|
|
|
@ -6,7 +6,7 @@ from ihatemoney.tests.common.ihatemoney_testcase import IhatemoneyTestCase
|
||||||
from ihatemoney.utils import list_of_dicts2csv, list_of_dicts2json
|
from ihatemoney.utils import list_of_dicts2csv, list_of_dicts2json
|
||||||
|
|
||||||
|
|
||||||
class CommonTestCase(object):
|
class CommonTestCase:
|
||||||
class Import(IhatemoneyTestCase):
|
class Import(IhatemoneyTestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
|
|
@ -8,7 +8,6 @@ import operator
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import smtplib
|
import smtplib
|
||||||
import socket
|
|
||||||
|
|
||||||
from babel import Locale
|
from babel import Locale
|
||||||
from babel.numbers import get_currency_name, get_currency_symbol
|
from babel.numbers import get_currency_name, get_currency_symbol
|
||||||
|
@ -50,7 +49,7 @@ def send_email(mail_message):
|
||||||
# to check for both.
|
# to check for both.
|
||||||
try:
|
try:
|
||||||
current_app.mail.send(mail_message)
|
current_app.mail.send(mail_message)
|
||||||
except (smtplib.SMTPException, socket.error):
|
except (smtplib.SMTPException, OSError):
|
||||||
return False
|
return False
|
||||||
# Email was sent successfully
|
# Email was sent successfully
|
||||||
return True
|
return True
|
||||||
|
@ -100,7 +99,7 @@ class Redirect303(HTTPException, RoutingException):
|
||||||
return redirect(self.new_url, 303)
|
return redirect(self.new_url, 303)
|
||||||
|
|
||||||
|
|
||||||
class PrefixedWSGI(object):
|
class PrefixedWSGI:
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Wrap the application in this middleware and configure the
|
Wrap the application in this middleware and configure the
|
||||||
|
@ -148,7 +147,7 @@ def minimal_round(*args, **kw):
|
||||||
|
|
||||||
def static_include(filename):
|
def static_include(filename):
|
||||||
fullpath = os.path.join(current_app.static_folder, filename)
|
fullpath = os.path.join(current_app.static_folder, filename)
|
||||||
with open(fullpath, "r") as f:
|
with open(fullpath) as f:
|
||||||
return f.read()
|
return f.read()
|
||||||
|
|
||||||
|
|
||||||
|
@ -284,7 +283,7 @@ def eval_arithmetic_expression(expr):
|
||||||
try:
|
try:
|
||||||
result = _eval(ast.parse(expr, mode="eval").body)
|
result = _eval(ast.parse(expr, mode="eval").body)
|
||||||
except (SyntaxError, TypeError, ZeroDivisionError, KeyError):
|
except (SyntaxError, TypeError, ZeroDivisionError, KeyError):
|
||||||
raise ValueError("Error evaluating expression: {}".format(expr))
|
raise ValueError(f"Error evaluating expression: {expr}")
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue