Skip to content

Commit

Permalink
style: pyupgrade --py36-plus
Browse files Browse the repository at this point in the history
  • Loading branch information
jerivas committed May 31, 2021
1 parent bb4cb57 commit 9178598
Show file tree
Hide file tree
Showing 96 changed files with 1,231 additions and 584 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
- name: Install dependencies
run: pip install tox -U pip
- name: Lint
run: tox -e package -e lint
run: tox -e package -e lint -e pyupgrade

# Create a new semantic release
release:
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
#
# Mezzanine documentation build configuration file, created by
# sphinx-quickstart on Wed Mar 10 07:20:42 2010.
Expand Down
2 changes: 1 addition & 1 deletion docs/docs_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

characters = "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)"
# Generate a SECRET_KEY for this build
SECRET_KEY = "".join([choice(characters) for i in range(50)])
SECRET_KEY = "".join(choice(characters) for i in range(50))

if "mezzanine.accounts" not in INSTALLED_APPS:
INSTALLED_APPS = tuple(INSTALLED_APPS) + ("mezzanine.accounts",)
2 changes: 1 addition & 1 deletion mezzanine/accounts/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def save_model(self, request, obj, form, change):
must_send_verification_mail_after_save = True
else:
send_approved_mail(request, obj)
super(UserProfileAdmin, self).save_model(request, obj, form, change)
super().save_model(request, obj, form, change)
if must_send_verification_mail_after_save:
user = User.objects.get(id=obj.id)
send_verification_mail(request, user, "signup_verify")
Expand Down
6 changes: 3 additions & 3 deletions mezzanine/accounts/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ class Meta:
exclude = _exclude_fields

def __init__(self, *args, **kwargs):
super(ProfileForm, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._signup = self.instance.id is None
user_fields = set([f.name for f in User._meta.get_fields()])
user_fields = {f.name for f in User._meta.get_fields()}
try:
self.fields["username"].help_text = ugettext(
"Only letters, numbers, dashes or underscores please"
Expand Down Expand Up @@ -197,7 +197,7 @@ def save(self, *args, **kwargs):
"""

kwargs["commit"] = False
user = super(ProfileForm, self).save(*args, **kwargs)
user = super().save(*args, **kwargs)
try:
self.cleaned_data["username"]
except KeyError:
Expand Down
22 changes: 12 additions & 10 deletions mezzanine/accounts/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,33 @@
_slash = "/" if settings.APPEND_SLASH else ""

urlpatterns = [
url(r"^%s%s$" % (LOGIN_URL.strip("/"), _slash), views.login, name="login"),
url(r"^%s%s$" % (LOGOUT_URL.strip("/"), _slash), views.logout, name="logout"),
url(r"^%s%s$" % (SIGNUP_URL.strip("/"), _slash), views.signup, name="signup"),
url(r"^{}{}$".format(LOGIN_URL.strip("/"), _slash), views.login, name="login"),
url(r"^{}{}$".format(LOGOUT_URL.strip("/"), _slash), views.logout, name="logout"),
url(r"^{}{}$".format(SIGNUP_URL.strip("/"), _slash), views.signup, name="signup"),
url(
r"^%s%s%s$" % (SIGNUP_VERIFY_URL.strip("/"), _verify_pattern, _slash),
r"^{}{}{}$".format(SIGNUP_VERIFY_URL.strip("/"), _verify_pattern, _slash),
views.signup_verify,
name="signup_verify",
),
url(
r"^%s%s$" % (PROFILE_UPDATE_URL.strip("/"), _slash),
r"^{}{}$".format(PROFILE_UPDATE_URL.strip("/"), _slash),
views.profile_update,
name="profile_update",
),
url(
r"^%s%s$" % (PASSWORD_RESET_URL.strip("/"), _slash),
r"^{}{}$".format(PASSWORD_RESET_URL.strip("/"), _slash),
views.password_reset,
name="mezzanine_password_reset",
),
url(
r"^%s%s%s$" % (PASSWORD_RESET_VERIFY_URL.strip("/"), _verify_pattern, _slash),
r"^{}{}{}$".format(
PASSWORD_RESET_VERIFY_URL.strip("/"), _verify_pattern, _slash
),
views.password_reset_verify,
name="password_reset_verify",
),
url(
r"^%s%s$" % (ACCOUNT_URL.strip("/"), _slash),
r"^{}{}$".format(ACCOUNT_URL.strip("/"), _slash),
views.account_redirect,
name="account_redirect",
),
Expand All @@ -61,12 +63,12 @@
if settings.ACCOUNTS_PROFILE_VIEWS_ENABLED:
urlpatterns += [
url(
r"^%s%s$" % (PROFILE_URL.strip("/"), _slash),
r"^{}{}$".format(PROFILE_URL.strip("/"), _slash),
views.profile_redirect,
name="profile_redirect",
),
url(
r"^%s/(?P<username>.*)%s$" % (PROFILE_URL.strip("/"), _slash),
r"^{}/(?P<username>.*){}$".format(PROFILE_URL.strip("/"), _slash),
views.profile,
name="profile",
),
Expand Down
6 changes: 3 additions & 3 deletions mezzanine/bin/management/commands/mezzanine_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Command(BaseCommand):
help = BaseCommand.help.replace("Django", "Mezzanine")

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"-a",
"--alternate",
Expand All @@ -35,7 +35,7 @@ def handle(self, *args, **options):
# Indicate that local_settings.py.template should be rendered
options["files"].append("local_settings.py.template")

super(Command, self).handle(*args, **options)
super().handle(*args, **options)

target = options.get("target", None)
name = options["name"]
Expand Down Expand Up @@ -98,4 +98,4 @@ def handle_template(self, template, subdir):
"""
if template is None:
return str(os.path.join(mezzanine.__path__[0], subdir))
return super(Command, self).handle_template(template, subdir)
return super().handle_template(template, subdir)
8 changes: 4 additions & 4 deletions mezzanine/blog/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, *args, **kwargs):
self.tag = kwargs.pop("tag", None)
self.category = kwargs.pop("category", None)
self.username = kwargs.pop("username", None)
super(PostsRSS, self).__init__(*args, **kwargs)
super().__init__(*args, **kwargs)
self._public = True
page = None
if "mezzanine.pages" in settings.INSTALLED_APPS:
Expand All @@ -51,7 +51,7 @@ def __init__(self, *args, **kwargs):
self._public = not page.login_required
if self._public:
if page is not None:
self._title = "%s | %s" % (page.title, settings.SITE_TITLE)
self._title = f"{page.title} | {settings.SITE_TITLE}"
self._description = strip_tags(page.description)
else:
self._title = settings.SITE_TITLE
Expand All @@ -60,7 +60,7 @@ def __init__(self, *args, **kwargs):
def __call__(self, *args, **kwarg):
self._request = current_request()
self._site = Site.objects.get(id=current_site_id())
return super(PostsRSS, self).__call__(*args, **kwarg)
return super().__call__(*args, **kwarg)

def add_domain(self, link):
return add_domain(self._site.domain, link, self._request.is_secure())
Expand Down Expand Up @@ -112,7 +112,7 @@ def feed_url(self):
return self.add_domain(self._request.path)

def item_link(self, item):
return self.add_domain(super(PostsRSS, self).item_link(item))
return self.add_domain(super().item_link(item))

def item_author_name(self, item):
return item.user.get_full_name() or item.user.username
Expand Down
2 changes: 1 addition & 1 deletion mezzanine/blog/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ def __init__(self):
for field in hidden_field_defaults:
initial[field] = BlogPost._meta.get_field(field).default
initial["status"] = CONTENT_STATUS_DRAFT
super(BlogPostForm, self).__init__(initial=initial)
super().__init__(initial=initial)
for field in hidden_field_defaults:
self.fields[field].widget = forms.HiddenInput()
2 changes: 1 addition & 1 deletion mezzanine/blog/management/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def add_arguments(self, parser):
def __init__(self, **kwargs):
self.posts = []
self.pages = []
super(BaseImporterCommand, self).__init__(**kwargs)
super().__init__(**kwargs)

def add_post(
self,
Expand Down
2 changes: 1 addition & 1 deletion mezzanine/blog/management/commands/import_blogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"-b",
"--blogger-id",
Expand Down
8 changes: 4 additions & 4 deletions mezzanine/blog/management/commands/import_blogml.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"-x",
"--xmldumpfname",
Expand Down Expand Up @@ -69,7 +69,7 @@ def _process_post_element(post_element, blog_categories):
)
]
post_dict["categories"] = list(
(blog_categories[category_id] for category_id in post_category_refs)
blog_categories[category_id] for category_id in post_category_refs
)
post_dict["tags"] = [
x.attrib["ref"]
Expand Down Expand Up @@ -100,9 +100,9 @@ def _process_categories(root_tree):
cat_elements = root_tree.findall(
search_paths["find_categories"], namespaces=ns
)
cat_ids = tuple((x.attrib["id"] for x in cat_elements))
cat_ids = tuple(x.attrib["id"] for x in cat_elements)
cat_title_txt = tuple(
(x.find("blogml:title", namespaces=ns).text for x in cat_elements)
x.find("blogml:title", namespaces=ns).text for x in cat_elements
)
categories_dict = dict(zip(cat_ids, cat_title_txt))
return categories_dict
Expand Down
4 changes: 2 additions & 2 deletions mezzanine/blog/management/commands/import_posterous.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"-a", "--api-token", dest="api_token", help="Posterous API Key"
)
Expand Down Expand Up @@ -97,7 +97,7 @@ def handle_import(self, options):
)
if not post["comments_count"]:
continue
path = "sites/%s/posts/%s/comments" % (site["id"], post["id"])
path = "sites/{}/posts/{}/comments".format(site["id"], post["id"])
time.sleep(2)
comments = self.request(path)
for comment in comments:
Expand Down
2 changes: 1 addition & 1 deletion mezzanine/blog/management/commands/import_rss.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument("-r", "--rss-url", dest="rss_url", help="RSS feed URL")
parser.add_argument(
"-p",
Expand Down
8 changes: 4 additions & 4 deletions mezzanine/blog/management/commands/import_tumblr.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument(
"-t", "--tumblr-user", dest="tumblr_user", help="Tumblr username"
)
Expand All @@ -51,7 +51,7 @@ def handle_import(self, options):
while True:
retries = MAX_RETRIES_PER_CALL
try:
call_url = "%s?start=%s" % (json_url, start_index)
call_url = f"{json_url}?start={start_index}"
if verbosity >= 2:
print("Calling %s" % call_url)
response = urlopen(call_url)
Expand All @@ -67,8 +67,8 @@ def handle_import(self, options):
sleep(3)
continue
elif response.code != 200:
raise IOError("HTTP status %s" % response.code)
except IOError as e:
raise OSError("HTTP status %s" % response.code)
except OSError as e:
error = "Error communicating with Tumblr API (%s)" % e
raise CommandError(error)

Expand Down
4 changes: 2 additions & 2 deletions mezzanine/blog/management/commands/import_wordpress.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Command(BaseImporterCommand):
"""

def add_arguments(self, parser):
super(Command, self).add_arguments(parser)
super().add_arguments(parser)
parser.add_argument("-u", "--url", dest="url", help="URL to import file")

def get_text(self, xml, name):
Expand All @@ -27,7 +27,7 @@ def get_text(self, xml, name):
"""
nodes = xml.getElementsByTagName("wp:comment_" + name)[0].childNodes
accepted_types = [Node.CDATA_SECTION_NODE, Node.TEXT_NODE]
return "".join([n.data for n in nodes if n.nodeType in accepted_types])
return "".join(n.data for n in nodes if n.nodeType in accepted_types)

def handle_import(self, options):
"""
Expand Down
Loading

0 comments on commit 9178598

Please sign in to comment.