Skip to content

Commit

Permalink
Run pyupgrade ⚡️
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaoming committed Feb 18, 2024
1 parent 62f0c57 commit 986223b
Show file tree
Hide file tree
Showing 22 changed files with 49 additions and 56 deletions.
10 changes: 4 additions & 6 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ def process_docstring(app, what, name, obj, options, lines):
if help_text:
# Add the model field to the end of the docstring as a param
# using the help text as the description
lines.append(":param %s: %s" % (field.attname, help_text))
lines.append(f":param {field.attname}: {help_text}")
else:
# Add the model field to the end of the docstring as a param
# using the verbose name as the description
lines.append(":param %s: %s" % (field.attname, verbose_name))
lines.append(f":param {field.attname}: {verbose_name}")

# Add the field's type to the docstring
if isinstance(field, models.ForeignKey):
Expand All @@ -86,9 +86,7 @@ def process_docstring(app, what, name, obj, options, lines):
% (field.attname, type(field).__name__, to)
)
else:
lines.append(
":type %s: %s" % (field.attname, type(field).__name__)
)
lines.append(f":type {field.attname}: {type(field).__name__}")

return lines

Expand Down Expand Up @@ -131,7 +129,7 @@ def setup(app):

# General information about the project.
project = "django-wiki"
copyright = "{}, Benjamin Bach".format(datetime.now().year) # noqa
copyright = f"{datetime.now().year}, Benjamin Bach" # noqa


path = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/conf/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
"dt",
"dd",
}
).union({"h{}".format(n) for n in range(1, 7)})
).union({f"h{n}" for n in range(1, 7)})


#: List of allowed tags in Markdown article contents.
Expand Down
4 changes: 2 additions & 2 deletions src/wiki/core/markdown/mdx/codehilite.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def highlight(code, config, tab_length, lang=None):
lang=lang,
)
html = code.hilite()
html = """<div class="codehilite-wrap">{}</div>""".format(html)
html = f"""<div class="codehilite-wrap">{html}</div>"""
return html


Expand Down Expand Up @@ -67,7 +67,7 @@ def run(self, lines):
m.group("code"), self.config, self.md.tab_length, lang=lang
)
placeholder = self.md.htmlStash.store(html)
text = "%s\n%s\n%s" % (
text = "{}\n{}\n{}".format(
text[: m.start()],
placeholder,
text[m.end() :],
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def wrapper(request, *args, **kwargs):
except NoRootURL:
return redirect("wiki:root_create")
except models.Article.DoesNotExist:
raise Http404("Article id {:} not found".format(article_id))
raise Http404(f"Article id {article_id} not found")

Check warning on line 116 in src/wiki/decorators.py

View check run for this annotation

Codecov / codecov/patch

src/wiki/decorators.py#L116

Added line #L116 was not covered by tests
except models.URLPath.DoesNotExist:
try:
pathlist = list(
Expand Down
6 changes: 3 additions & 3 deletions src/wiki/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name="urlpath",
unique_together=set([("site", "parent", "slug")]),
unique_together={("site", "parent", "slug")},
),
migrations.AddField(
model_name="revisionplugin",
Expand All @@ -397,7 +397,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name="articlerevision",
unique_together=set([("article", "revision_number")]),
unique_together={("article", "revision_number")},
),
migrations.AddField(
model_name="articleplugin",
Expand All @@ -409,7 +409,7 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name="articleforobject",
unique_together=set([("content_type", "object_id")]),
unique_together={("content_type", "object_id")},
),
migrations.AddField(
model_name="article",
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/attachments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __str__(self):
from wiki.models import Article

try:
return "%s: %s" % (
return "{}: {}".format(

Check warning on line 63 in src/wiki/plugins/attachments/models.py

View check run for this annotation

Codecov / codecov/patch

src/wiki/plugins/attachments/models.py#L63

Added line #L63 was not covered by tests
self.article.current_revision.title,
self.original_filename,
)
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/editsection/markdown_extensions.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def ensure_unique_id(self, node):
candidate = slug
i = 1
while candidate in self.slugs:
candidate = "{}_{}".format(slug, i)
candidate = f"{slug}_{i}"

Check warning on line 120 in src/wiki/plugins/editsection/markdown_extensions.py

View check run for this annotation

Codecov / codecov/patch

src/wiki/plugins/editsection/markdown_extensions.py#L120

Added line #L120 was not covered by tests
i += 1
self.slugs[candidate] = True
node.attrib["id"] = candidate
Expand Down
4 changes: 2 additions & 2 deletions src/wiki/plugins/editsection/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def dispatch(self, request, article, *args, **kwargs):
else:
messages.error(
request,
"{} {}".format(ERROR_SECTION_CHANGED, ERROR_TRY_AGAIN),
f"{ERROR_SECTION_CHANGED} {ERROR_TRY_AGAIN}",
)
return self._redirect_to_article()
else:
Expand Down Expand Up @@ -129,7 +129,7 @@ def form_valid(self, form):
self.article.save()
messages.error(
self.request,
"{} {}".format(ERROR_ARTICLE_CHANGED, ERROR_TRY_AGAIN),
f"{ERROR_ARTICLE_CHANGED} {ERROR_TRY_AGAIN}",
)

return self._redirect_to_article()
2 changes: 1 addition & 1 deletion src/wiki/plugins/images/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def inherit_predecessor(self, image, skip_image_file=False):
self.image = predecessor.image
self.width = predecessor.width
self.height = predecessor.height
except IOError:
except OSError:

Check warning on line 103 in src/wiki/plugins/images/models.py

View check run for this annotation

Codecov / codecov/patch

src/wiki/plugins/images/models.py#L103

Added line #L103 was not covered by tests
self.image = None

class Meta:
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/macros/mdx/toc.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

def process_toc_depth(toc_depth):
if isinstance(toc_depth, str) and "-" in toc_depth:
toc_top, toc_bottom = [int(x) for x in toc_depth.split("-")]
toc_top, toc_bottom = (int(x) for x in toc_depth.split("-"))
else:
toc_top = 1
toc_bottom = int(toc_depth)
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/macros/mdx/wikilinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def build_url(label, base, end, md):
if urlpath.children.filter(slug=clean_label).exists():
base = ""
break
return "%s%s%s" % (base, clean_label, end)
return f"{base}{clean_label}{end}"


class WikiLinkExtension(Extension):
Expand Down
2 changes: 1 addition & 1 deletion src/wiki/plugins/notifications/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ class Migration(migrations.Migration):
),
migrations.AlterUniqueTogether(
name="articlesubscription",
unique_together=set([("subscription", "articleplugin_ptr")]),
unique_together={("subscription", "articleplugin_ptr")},
),
]
3 changes: 1 addition & 2 deletions src/wiki/plugins/pymdown/templatetags/wiki_pymdown_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,4 @@

@register.simple_tag
def allowed_pymdown_macros():
for method in settings.pymdown_docs:
yield method
yield from settings.pymdown_docs
2 changes: 1 addition & 1 deletion src/wiki/templatetags/wiki_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def clean_text(content):
after_words = all_after[: max_words - len(before_words)]
before = " ".join(before_words)
after = " ".join(after_words)
html = ("%s %s %s" % (before, striptags(match), after)).strip()
html = (f"{before} {striptags(match)} {after}").strip()
kw_p = re.compile(r"(\S*%s\S*)" % keyword, re.IGNORECASE)
html = kw_p.sub(r"<strong>\1</strong>", html)

Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def test_cache(self):
)
expected = """<h1 id="wiki-toc-header">header""" """.*</h1>"""
# cached content does not exist yet. this will create it
self.assertRegexpMatches(a.get_cached_content(), expected)
self.assertRegex(a.get_cached_content(), expected)
# actual cached content test
self.assertRegexpMatches(a.get_cached_content(), expected)
self.assertRegex(a.get_cached_content(), expected)

def test_articlerevision_presave_signals(self):
a = Article.objects.create()
Expand Down
4 changes: 2 additions & 2 deletions tests/core/test_template_tags.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,14 +211,14 @@ def test_called_with_preview_content_and_article_have_current_revision(
output = wiki_render({}, article, preview_content=content)
self.assertCountEqual(self.keys, output)
self.assertEqual(output["article"], article)
self.assertRegexpMatches(output["content"], expected)
self.assertRegex(output["content"], expected)
self.assertIs(output["preview"], True)
self.assertEqual(output["plugins"], {"spam": "eggs"})
self.assertEqual(output["STATIC_URL"], django_settings.STATIC_URL)
self.assertEqual(output["CACHE_TIMEOUT"], settings.CACHE_TIMEOUT)

output = self.render({"article": article, "pc": content})
self.assertRegexpMatches(output, expected)
self.assertRegex(output, expected)

def test_called_with_preview_content_and_article_dont_have_current_revision(
self
Expand Down
18 changes: 8 additions & 10 deletions tests/core/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ class ArticleViewViewTests(
def dump_db_status(self, message=""):
"""Debug printing of the complete important database content."""

print("*** db status *** {}".format(message))
print(f"*** db status *** {message}")

from wiki.models import Article, ArticleRevision

for klass in (Article, ArticleRevision, URLPath):
print("* {} *".format(klass.__name__))
print(f"* {klass.__name__} *")
pprint.pprint(list(klass.objects.values()), width=240)

def test_redirects_to_create_if_the_slug_is_unknown(self):
Expand Down Expand Up @@ -186,16 +186,14 @@ def test_show_max_children(self):
response = self.client.post(
resolve_url("wiki:create", path="wikiroot/"),
{
"title": "Sub Article {0}".format(idx),
"slug": "SubArticle{0}".format(idx),
"content": "Sub Article {0}".format(idx),
"title": f"Sub Article {idx}",
"slug": f"SubArticle{idx}",
"content": f"Sub Article {idx}",
},
)
self.assertRedirects(
response,
resolve_url(
"wiki:get", path="wikiroot/subarticle{0}/".format(idx)
),
resolve_url("wiki:get", path=f"wikiroot/subarticle{idx}/"),
)
response = self.client.get(
reverse("wiki:get", kwargs={"path": "wikiroot/"})
Expand Down Expand Up @@ -785,11 +783,11 @@ def test_merge_preview(self):
self.assertContains(response, "Previewing merge between:")
self.assertContains(
response,
"#{rev_number}".format(rev_number=first_revision.revision_number),
f"#{first_revision.revision_number}",
)
self.assertContains(
response,
"#{rev_number}".format(rev_number=new_revision.revision_number),
f"#{new_revision.revision_number}",
)


Expand Down
8 changes: 4 additions & 4 deletions tests/plugins/attachments/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,25 +159,25 @@ def test_render(self):
r'<span class="attachment"><a href=".*attachments/download/1/"'
r' title="Click to download test\.txt">\s*test\.txt\s*</a>'
)
self.assertRegexpMatches(output, expected)
self.assertRegex(output, expected)

def test_render_missing(self):
output = self.get_article("[attachment:2]")
expected = r'<span class="attachment attachment-deleted">\s*Attachment with ID #2 is deleted.\s*</span>'
self.assertRegexpMatches(output, expected)
self.assertRegex(output, expected)

def test_render_title(self):
output = self.get_article('[attachment:1 title:"Test title"]')
expected = (
r'<span class="attachment"><a href=".*attachments/download/1/"'
r' title="Click to download test\.txt">\s*Test title\s*</a>'
)
self.assertRegexpMatches(output, expected)
self.assertRegex(output, expected)

def test_render_title_size(self):
output = self.get_article('[attachment:1 title:"Test title 2" size]')
expected = (
r'<span class="attachment"><a href=".*attachments/download/1/"'
r' title="Click to download test\.txt">\s*Test title 2 \[25[^b]bytes\]\s*</a>'
)
self.assertRegexpMatches(output, expected)
self.assertRegex(output, expected)
16 changes: 8 additions & 8 deletions tests/plugins/globalhistory/test_globalhistory.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_history(self):

response = self.client.get(url)
expected = "(?s).*Root Article.*no log message.*"
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

URLPath.create_urlpath(
URLPath.root(),
Expand All @@ -30,7 +30,7 @@ def test_history(self):
expected = (
"(?s).*TestHistory1.*Comment 1.*" "Root Article.*no log message.*"
)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

urlpath = URLPath.create_urlpath(
URLPath.root(),
Expand All @@ -45,13 +45,13 @@ def test_history(self):
"Root Article.*no log message.*"
)
response = self.client.get(url)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

response = self.client.get(url0)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

response = self.client.get(url1)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

response = self.client.post(
reverse("wiki:edit", kwargs={"path": "testhistory2/"}),
Expand All @@ -72,18 +72,18 @@ def test_history(self):
"Root Article.*no log message.*"
)
response = self.client.get(url)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

response = self.client.get(url0)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

expected = (
"(?s).*TestHistory2Mod.*Testing Revision.*"
"TestHistory1.*Comment 1.*"
"Root Article.*no log message.*"
)
response = self.client.get(url1)
self.assertRegexpMatches(response.rendered_content, expected)
self.assertRegex(response.rendered_content, expected)

def test_translation(self):
# Test that translation of "List of %s changes in the wiki." exists.
Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/images/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def _create_test_image(self, path):
plugin_index, 0, msg="Image plugin not activated"
)
base_edit_url = reverse("wiki:edit", kwargs={"path": path})
url = base_edit_url + "?f=form{0:d}".format(plugin_index)
url = base_edit_url + f"?f=form{plugin_index:d}"
filestream = self._create_gif_filestream_from_base64(self.test_data)
response = self.client.post(
url,
Expand Down
6 changes: 2 additions & 4 deletions tests/plugins/notifications/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ def test_change_settings(self):
"MIN_NUM_FORMS",
"MAX_NUM_FORMS",
):
data["%s-%s" % (management_form.prefix, i)] = management_form[
i
].value()
data[f"{management_form.prefix}-{i}"] = management_form[i].value()

for i in range(response.context["form"].total_form_count()):
# get form index 'i'
Expand All @@ -55,7 +53,7 @@ def test_change_settings(self):
# retrieve all the fields
for field_name in current_form.fields:
value = current_form[field_name].value()
data["%s-%s" % (current_form.prefix, field_name)] = (
data[f"{current_form.prefix}-{field_name}"] = (
value if value is not None else ""
)

Expand Down
2 changes: 1 addition & 1 deletion tests/plugins/redlinks/test_redlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def test_absolute_external(self):

def test_absolute_internal(self):
wiki_root = reverse("wiki:get", kwargs={"path": ""})
self.assert_internal(self.root, "[Server Root]({:})".format(wiki_root))
self.assert_internal(self.root, f"[Server Root]({wiki_root})")

def test_child_to_broken(self):
self.assert_broken(self.child, "[Broken](../broken/)")
Expand Down

0 comments on commit 986223b

Please sign in to comment.