Skip to content

Commit eefdbfa

Browse files
committed
Update ruff to >=0.9
Update `ruff` and code for the "2025 style guide"
1 parent 95a5abb commit eefdbfa

21 files changed

+65
-76
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ repos:
6969
- --comment-style
7070
- "|#|"
7171
- repo: https://github.com/astral-sh/ruff-pre-commit
72-
rev: v0.8.6
72+
rev: v0.9.1
7373
hooks:
7474
- id: ruff
7575
- id: ruff-format

bedrock/base/tests/test_accepted_locales.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@ def setup_class(cls):
4040
"""
4141
if os.path.exists(cls.locale_bkp):
4242
raise Exception(
43-
"A backup of locale/ exists at %s which might "
44-
"mean that previous tests didn't end cleanly. "
45-
"Skipping the test suite." % cls.locale_bkp
43+
"A backup of locale/ exists at %s which might mean that previous tests didn't end cleanly. Skipping the test suite." % cls.locale_bkp
4644
)
4745
cls.DEV = settings.DEV
4846
cls.PROD_LANGUAGES = settings.PROD_LANGUAGES

bedrock/careers/utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55

66
def generate_position_meta_description(position):
77
suffix = "n" if position.position_type.lower().startswith(("a", "e", "i", "o", "u")) else ""
8-
meta = f"Mozilla is hiring a{suffix} " f"{position.position_type.lower()} {position.title} in "
8+
meta = f"Mozilla is hiring a{suffix} {position.position_type.lower()} {position.title} in "
99

1010
if len(position.location_list) > 1:
11-
meta = meta + f'{", ".join(position.location_list[:-1])} and {position.location_list[-1]}'
11+
meta = meta + f"{', '.join(position.location_list[:-1])} and {position.location_list[-1]}"
1212
else:
1313
meta = meta + position.location_list[0]
1414

bedrock/contentful/api.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _get_card_image_url(image, width, aspect):
136136

137137

138138
def _get_product_class(product):
139-
return f'mzp-t-product-{PRODUCT_THEMES.get(product, "")}'
139+
return f"mzp-t-product-{PRODUCT_THEMES.get(product, '')}"
140140

141141

142142
def _get_layout_class(layout):
@@ -148,11 +148,11 @@ def _get_abbr_from_width(width):
148148

149149

150150
def _get_aspect_ratio_class(aspect_ratio):
151-
return f'mzp-has-aspect-{ASPECT_RATIOS.get(aspect_ratio, "")}'
151+
return f"mzp-has-aspect-{ASPECT_RATIOS.get(aspect_ratio, '')}"
152152

153153

154154
def _get_width_class(width):
155-
return f'mzp-t-content-{WIDTHS.get(width, "")}' if width else ""
155+
return f"mzp-t-content-{WIDTHS.get(width, '')}" if width else ""
156156

157157

158158
def _get_theme_class(theme):
@@ -208,7 +208,7 @@ def _make_cta_button(entry):
208208
# TODO, only add on Firefox themed pages
209209
"mzp-t-product" if action != "Get Mozilla VPN" and action != "Get MDN Plus" else "",
210210
"mzp-t-secondary" if fields.get("theme") == "Secondary" else "",
211-
f'mzp-t-{WIDTHS.get(fields.get("size"), "")}' if fields.get("size") else "",
211+
f"mzp-t-{WIDTHS.get(fields.get('size'), '')}" if fields.get("size") else "",
212212
]
213213
data = {
214214
"action": action,

bedrock/contentful/migrations/0003_add_classification_category_and_tags_fields_to_contentfulentry.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@ class Migration(migrations.Migration):
2727
blank=True,
2828
default="",
2929
help_text=(
30-
"Some pages may have custom fields on them, distinct "
31-
"from their content type - eg: pagePageResourceCenter has a 'Product' field"
30+
"Some pages may have custom fields on them, distinct from their content type - eg: pagePageResourceCenter has a 'Product' field"
3231
),
3332
max_length=255,
3433
),

bedrock/contentful/tests/test_contentful_api.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ def test_LinkRenderer__mozilla_link__existing_utm(mock_get_current_request):
534534
mozilla_mock_hyperlink_node = deepcopy(mock_hyperlink_node)
535535
mozilla_mock_hyperlink_node["data"]["uri"] = "https://mozilla.org/test/page/?utm_source=UTMTEST"
536536
output = LinkRenderer({"text": TextRenderer}).render(mozilla_mock_hyperlink_node)
537-
expected = '<a href="https://mozilla.org/test/page/?utm_source=UTMTEST" ' 'data-cta-text="Example" rel="external noopener">Example</a>'
537+
expected = '<a href="https://mozilla.org/test/page/?utm_source=UTMTEST" data-cta-text="Example" rel="external noopener">Example</a>'
538538

539539
assert output == expected
540540

bedrock/contentful/tests/test_contentful_commands.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ def test_update_contentful__detect_and_delete_absent_entries(
683683
for idx in range(total_to_create_per_locale):
684684
ContentfulEntry.objects.create(
685685
content_type=CONTENT_TYPE_PAGE_RESOURCE_CENTER,
686-
contentful_id=f"entry_{idx+1}",
686+
contentful_id=f"entry_{idx + 1}",
687687
locale=locale,
688688
)
689689

@@ -710,7 +710,7 @@ def test_update_contentful__detect_and_delete_absent_entries__homepage_involved(
710710
for idx in range(3):
711711
ContentfulEntry.objects.create(
712712
content_type=CONTENT_TYPE_PAGE_RESOURCE_CENTER,
713-
contentful_id=f"entry_{idx+1}",
713+
contentful_id=f"entry_{idx + 1}",
714714
locale=locale,
715715
)
716716

bedrock/contentful/tests/test_contentful_utils.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ def test_locales_with_available_content(
6464
for i in range(count):
6565
ContentfulEntry.objects.create(
6666
content_type=content_type,
67-
contentful_id=f"entry_{i+1}",
67+
contentful_id=f"entry_{i + 1}",
6868
classification=classification,
6969
locale=locale,
7070
localisation_complete=True,
7171
)
7272
# Add some with incomplete localisation as control
7373
ContentfulEntry.objects.create(
7474
content_type=content_type,
75-
contentful_id=f"entry_{i+100}",
75+
contentful_id=f"entry_{i + 100}",
7676
classification=classification,
7777
locale=locale,
7878
localisation_complete=False,

bedrock/mozorg/forms.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def render(self, name, value, attrs=None, renderer=None):
3434

3535
policy_txt = ftl("newsletter-form-im-okay-with-mozilla", url=reverse("privacy.notices.websites"))
3636

37-
return mark_safe(f"""<label for="{attrs['id']}" class="privacy-check-label">{input_txt}<span class="title">{policy_txt}</span></label>""")
37+
return mark_safe(f"""<label for="{attrs["id"]}" class="privacy-check-label">{input_txt}<span class="title">{policy_txt}</span></label>""")
3838

3939

4040
class HoneyPotWidget(widgets.TextInput):

bedrock/mozorg/management/commands/update_product_details_files.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def __init__(self, stdout=None, stderr=None, no_color=False):
3939

4040
def add_arguments(self, parser):
4141
parser.add_argument("-q", "--quiet", action="store_true", dest="quiet", default=False, help="If no error occurs, swallow all output.")
42-
parser.add_argument("--database", default="default", help=("Specifies the database to use, if using a db. " 'Defaults to "default".'))
42+
parser.add_argument("--database", default="default", help=('Specifies the database to use, if using a db. Defaults to "default".'))
4343
parser.add_argument("-f", "--force", action="store_true", dest="force", default=False, help="Load the data even if nothing new from git.")
4444

4545
def handle(self, *args, **options):

bedrock/mozorg/templatetags/misc.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ def l10n_css(ctx):
149149
locale = getattr(ctx["request"], "locale", "en-US")
150150

151151
if _l10n_media_exists("css", locale, "intl.css"):
152-
markup = '<link rel="stylesheet" media="screen,projection,tv" href=' '"%s">' % static(path.join("css", "l10n", locale, "intl.css"))
152+
markup = '<link rel="stylesheet" media="screen,projection,tv" href="%s">' % static(path.join("css", "l10n", locale, "intl.css"))
153153
else:
154154
markup = ""
155155

@@ -708,7 +708,7 @@ def _fxa_product_button(
708708
if class_name:
709709
css_class += f" {class_name}"
710710

711-
markup = f'<a href="{href}" data-action="{settings.FXA_ENDPOINT}" class="{css_class}" {attrs}>' f"{button_text}" f"</a>"
711+
markup = f'<a href="{href}" data-action="{settings.FXA_ENDPOINT}" class="{css_class}" {attrs}>{button_text}</a>'
712712

713713
return Markup(markup)
714714

bedrock/mozorg/tests/test_helper_misc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class TestL10nCSS(TestCase):
106106
static_url_dev = "/static/"
107107
cdn_url = "//mozorg.cdn.mozilla.net"
108108
static_url_prod = cdn_url + static_url_dev
109-
markup = '<link rel="stylesheet" media="screen,projection,tv" href=' '"%scss/l10n/%s/intl.css">'
109+
markup = '<link rel="stylesheet" media="screen,projection,tv" href="%scss/l10n/%s/intl.css">'
110110

111111
def _render(self, locale):
112112
req = self.rf.get("/")

bedrock/products/templatetags/misc.py

+10-19
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,15 @@ def _vpn_get_ga_data(selected_plan):
3939
analytics = selected_plan.get("analytics")
4040

4141
ga_data = (
42-
"{"
43-
"'id' : '%s',"
44-
"'brand' : '%s',"
45-
"'plan' : '%s',"
46-
"'period' : '%s',"
47-
"'price' : '%s',"
48-
"'discount' : '%s',"
49-
"'currency' : '%s'"
50-
"}"
51-
% (
52-
id,
53-
analytics.get("brand"),
54-
analytics.get("plan"),
55-
analytics.get("period"),
56-
analytics.get("price"),
57-
analytics.get("discount"),
58-
analytics.get("currency"),
59-
)
42+
f"{{"
43+
f"'id' : '{id}',"
44+
f"'brand' : '{analytics.get('brand')}',"
45+
f"'plan' : '{analytics.get('plan')}',"
46+
f"'period' : '{analytics.get('period')}',"
47+
f"'price' : '{analytics.get('price')}',"
48+
f"'discount' : '{analytics.get('discount')}',"
49+
f"'currency' : '{analytics.get('currency')}'"
50+
f"}}"
6051
)
6152

6253
return ga_data
@@ -107,7 +98,7 @@ def _vpn_product_link(product_url, entrypoint, link_text, class_name=None, optio
10798
if class_name:
10899
css_class += f" {class_name}"
109100

110-
markup = f'<a href="{href}" data-action="{settings.FXA_ENDPOINT}" class="{css_class}" {attrs}>' f"{link_text}" f"</a>"
101+
markup = f'<a href="{href}" data-action="{settings.FXA_ENDPOINT}" class="{css_class}" {attrs}>{link_text}</a>'
111102

112103
return Markup(markup)
113104

bedrock/products/tests/test_helper_misc.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,8 @@ def test_vpn_supported_locale(locale):
512512
@pytest.mark.parametrize(
513513
"locale",
514514
[
515-
"ach" "br",
515+
"ach",
516+
"br",
516517
"sco",
517518
"xh",
518519
],

bedrock/products/tests/test_views.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,10 @@ def setUp(self):
388388
classification=CONTENT_CLASSIFICATION_VPN,
389389
locale=locale,
390390
localisation_complete=True,
391-
contentful_id=f"entry_{i+1}",
392-
slug=f"slug-{i+1}",
391+
contentful_id=f"entry_{i + 1}",
392+
slug=f"slug-{i + 1}",
393393
# We only get back the .data field, so let's put something useful in here to look for
394-
data={"slug_for_test": f"slug-{i+1}-{locale}"},
394+
data={"slug_for_test": f"slug-{i + 1}-{locale}"},
395395
)
396396

397397
def _request(
@@ -501,10 +501,10 @@ def setUp(self):
501501
classification=CONTENT_CLASSIFICATION_VPN,
502502
locale=locale,
503503
localisation_complete=True,
504-
contentful_id=f"entry_{i+1}",
505-
slug=f"slug-{i+1}",
504+
contentful_id=f"entry_{i + 1}",
505+
slug=f"slug-{i + 1}",
506506
# We only get back the .data field, so let's put something useful in here to look for
507-
data={"slug_for_test": f"slug-{i+1}-{locale}"},
507+
data={"slug_for_test": f"slug-{i + 1}-{locale}"},
508508
)
509509

510510
@patch("bedrock.products.views.l10n_utils.render", return_value=HttpResponse())

bedrock/releasenotes/views.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ def release_notes(request, version, product="Firefox"):
109109
"sort_num": 1,
110110
"note": f'<a class="mdn-icon" rel="external" '
111111
f'href="https://developer.mozilla.org/docs/Mozilla/Firefox/Releases/'
112-
f'{ release.major_version }">Developer Information</a>',
112+
f'{release.major_version}">Developer Information</a>',
113113
},
114114
)
115115

bedrock/security/models.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22
# License, v. 2.0. If a copy of the MPL was not distributed with this
33
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
44

5+
from functools import total_ordering
6+
57
from django.db import models
68
from django.template.defaultfilters import slugify
7-
from django.utils.functional import total_ordering
89

910
from django_extensions.db.fields import ModificationDateTimeField
1011
from django_extensions.db.fields.json import JSONField
@@ -26,6 +27,9 @@ class Meta:
2627
def __str__(self):
2728
return self.name
2829

30+
def __lt__(self, other):
31+
return self.name_tuple < other.name_tuple
32+
2933
def save(self, force_insert=False, force_update=False, using=None, update_fields=None):
3034
# do not use self.name_tuple because don't want ".0" on versions.
3135
product, vers = self.name_and_version
@@ -58,9 +62,6 @@ def html_id(self):
5862
def version(self):
5963
return self.name_tuple[1]
6064

61-
def __lt__(self, other):
62-
return self.name_tuple < other.name_tuple
63-
6465

6566
class SecurityAdvisory(models.Model):
6667
id = models.CharField(max_length=8, primary_key=True, db_index=True)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.ruff]
22
line-length = 150
3-
target-version = 'py39'
3+
target-version = 'py312'
44
extend-exclude = ["docs", "assets", "static", "bedrock/externalfiles/files_cache"]
55

66
[tool.ruff.lint]

requirements/dev.in

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pytest-parallel==0.1.1
2020
pytest-rerunfailures==14.0
2121
pytest-selenium==4.0.1
2222
responses==0.25.6
23-
ruff==0.8.6
23+
ruff==0.9.1
2424
selenium==4.9.1 # Pinned to 4.9.1 until https://github.com/pytest-dev/pytest-selenium/issues/315 is resolved
2525
translate-toolkit==3.14.5
2626
uv==0.5.18

requirements/dev.txt

+19-19
Original file line numberDiff line numberDiff line change
@@ -2055,25 +2055,25 @@ rsa==4.9 \
20552055
# via
20562056
# -r requirements/prod.txt
20572057
# google-auth
2058-
ruff==0.8.6 \
2059-
--hash=sha256:0509e8da430228236a18a677fcdb0c1f102dd26d5520f71f79b094963322ed25 \
2060-
--hash=sha256:0c000a471d519b3e6cfc9c6680025d923b4ca140ce3e4612d1a2ef58e11f11fe \
2061-
--hash=sha256:248b1fb3f739d01d528cc50b35ee9c4812aa58cc5935998e776bf8ed5b251e75 \
2062-
--hash=sha256:45a56f61b24682f6f6709636949ae8cc82ae229d8d773b4c76c09ec83964a95a \
2063-
--hash=sha256:496dd38a53aa173481a7d8866bcd6451bd934d06976a2505028a50583e001b76 \
2064-
--hash=sha256:52d587092ab8df308635762386f45f4638badb0866355b2b86760f6d3c076188 \
2065-
--hash=sha256:54799ca3d67ae5e0b7a7ac234baa657a9c1784b48ec954a094da7c206e0365b1 \
2066-
--hash=sha256:61323159cf21bc3897674e5adb27cd9e7700bab6b84de40d7be28c3d46dc67cf \
2067-
--hash=sha256:7ae4478b1471fc0c44ed52a6fb787e641a2ac58b1c1f91763bafbc2faddc5117 \
2068-
--hash=sha256:7d7fc2377a04b6e04ffe588caad613d0c460eb2ecba4c0ccbbfe2bc973cbc162 \
2069-
--hash=sha256:91a7ddb221779871cf226100e677b5ea38c2d54e9e2c8ed847450ebbdf99b32d \
2070-
--hash=sha256:9257aa841e9e8d9b727423086f0fa9a86b6b420fbf4bf9e1465d1250ce8e4d8d \
2071-
--hash=sha256:bc3c083c50390cf69e7e1b5a5a7303898966be973664ec0c4a4acea82c1d4315 \
2072-
--hash=sha256:dcad24b81b62650b0eb8814f576fc65cfee8674772a6e24c9b747911801eeaa5 \
2073-
--hash=sha256:defed167955d42c68b407e8f2e6f56ba52520e790aba4ca707a9c88619e580e3 \
2074-
--hash=sha256:e169ea1b9eae61c99b257dc83b9ee6c76f89042752cb2d83486a7d6e48e8f764 \
2075-
--hash=sha256:e88b8f6d901477c41559ba540beeb5a671e14cd29ebd5683903572f4b40a9807 \
2076-
--hash=sha256:f1d70bef3d16fdc897ee290d7d20da3cbe4e26349f62e8a0274e7a3f4ce7a905
2058+
ruff==0.9.1 \
2059+
--hash=sha256:186c2313de946f2c22bdf5954b8dd083e124bcfb685732cfb0beae0c47233d9b \
2060+
--hash=sha256:1cd76c7f9c679e6e8f2af8f778367dca82b95009bc7b1a85a47f1521ae524fa7 \
2061+
--hash=sha256:2f312c86fb40c5c02b44a29a750ee3b21002bd813b5233facdaf63a51d9a85e1 \
2062+
--hash=sha256:342a824b46ddbcdddd3abfbb332fa7fcaac5488bf18073e841236aadf4ad5c19 \
2063+
--hash=sha256:39d0174ccc45c439093971cc06ed3ac4dc545f5e8bdacf9f067adf879544d969 \
2064+
--hash=sha256:3cae39ba5d137054b0e5b472aee3b78a7c884e61591b100aeb544bcd1fc38d4f \
2065+
--hash=sha256:3f94942a3bb767675d9a051867c036655fe9f6c8a491539156a6f7e6b5f31831 \
2066+
--hash=sha256:46ebf5cc106cf7e7378ca3c28ce4293b61b449cd121b98699be727d40b79ba72 \
2067+
--hash=sha256:50c647ff96f4ba288db0ad87048257753733763b409b2faf2ea78b45c8bb7fcb \
2068+
--hash=sha256:5dc40a378a0e21b4cfe2b8a0f1812a6572fc7b230ef12cd9fac9161aa91d807f \
2069+
--hash=sha256:69572926c0f0c9912288915214ca9b2809525ea263603370b9e00bed2ba56dbd \
2070+
--hash=sha256:728d791b769cc28c05f12c280f99e8896932e9833fef1dd8756a6af2261fd1ab \
2071+
--hash=sha256:84330dda7abcc270e6055551aca93fdde1b0685fc4fd358f26410f9349cf1743 \
2072+
--hash=sha256:937267afce0c9170d6d29f01fcd1f4378172dec6760a9f4dface48cdabf9610a \
2073+
--hash=sha256:ae017c3a29bee341ba584f3823f805abbe5fe9cd97f87ed07ecbf533c4c88366 \
2074+
--hash=sha256:beb3298604540c884d8b282fe7625651378e1986c25df51dec5b2f60cafc31ce \
2075+
--hash=sha256:f0c8b149e9c7353cace7d698e1656ffcf1e36e50f8ea3b5d5f7f87ff9986a7ca \
2076+
--hash=sha256:fd2b25ecaf907d6458fa842675382c8597b3c746a2dde6717fe3415425df0c17
20772077
# via -r requirements/dev.in
20782078
s3transfer==0.10.4 \
20792079
--hash=sha256:244a76a24355363a68164241438de1b72f8781664920260c48465896b712a41e \

tests/redirects/map_globalconf.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -573,8 +573,7 @@
573573
# bug 1090468
574574
url_test(
575575
"/security/{older-alerts,security-announcement,phishing-test{,-results}}.html",
576-
"http://website-archive.mozilla.org/www.mozilla.org/security/security"
577-
"/{older-alerts,security-announcement,phishing-test{,-results}}.html",
576+
"http://website-archive.mozilla.org/www.mozilla.org/security/security/{older-alerts,security-announcement,phishing-test{,-results}}.html",
578577
),
579578
url_test(
580579
"/security/iSECPartners_Phishing.pdf", "http://website-archive.mozilla.org/www.mozilla.org/security/security/iSECPartners_Phishing.pdf"

0 commit comments

Comments
 (0)