Skip to content

Refactor 3-col-content #570

Refactor 3-col-content

Refactor 3-col-content #570

GitHub Actions / Black failed Jun 25, 2024 in 0s

28 errors

Black found 28 errors

Annotations

Check failure on line 30 in /home/runner/work/online-judge/online-judge/judge/admin/profile.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/admin/profile.py#L13-L30

 class ProfileForm(ModelForm):
     def __init__(self, *args, **kwargs):
         super(ProfileForm, self).__init__(*args, **kwargs)
         if "current_contest" in self.base_fields:
             # form.fields['current_contest'] does not exist when the user has only view permission on the model.
-            self.fields[
-                "current_contest"
-            ].queryset = self.instance.contest_history.select_related("contest").only(
-                "contest__name", "user_id", "virtual"
-            )
-            self.fields["current_contest"].label_from_instance = (
-                lambda obj: "%s v%d" % (obj.contest.name, obj.virtual)
+            self.fields["current_contest"].queryset = (
+                self.instance.contest_history.select_related("contest").only(
+                    "contest__name", "user_id", "virtual"
+                )
+            )
+            self.fields["current_contest"].label_from_instance = lambda obj: (
+                "%s v%d" % (obj.contest.name, obj.virtual)
                 if obj.virtual
                 else obj.contest.name
             )
 
     class Meta:

Check failure on line 282 in /home/runner/work/online-judge/online-judge/judge/admin/submission.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/admin/submission.py#L267-L282

                 "problem__points",
             )
         )
         for submission in submissions:
             submission.points = round(
-                submission.case_points
-                / submission.case_total
-                * submission.problem.points
-                if submission.case_total
-                else 0,
+                (
+                    submission.case_points
+                    / submission.case_total
+                    * submission.problem.points
+                    if submission.case_total
+                    else 0
+                ),
                 1,
             )
             if (
                 not submission.problem.partial
                 and submission.points < submission.problem.points

Check failure on line 173 in /home/runner/work/online-judge/online-judge/judge/contest_format/ecoo.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/contest_format/ecoo.py#L164-L173

 
     def display_participation_result(self, participation, show_final=False):
         return format_html(
             '<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
             points=floatformat(participation.score),
-            cumtime=nice_repr(timedelta(seconds=participation.cumtime), "noday")
-            if self.config["cumtime"]
-            else "",
+            cumtime=(
+                nice_repr(timedelta(seconds=participation.cumtime), "noday")
+                if self.config["cumtime"]
+                else ""
+            ),
         )

Check failure on line 130 in /home/runner/work/online-judge/online-judge/judge/contest_format/ioi.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/contest_format/ioi.py#L117-L130

                     ],
                 ),
                 points=floatformat(
                     format_data["points"], -self.contest.points_precision
                 ),
-                time=nice_repr(timedelta(seconds=format_data["time"]), "noday")
-                if self.config["cumtime"]
-                else "",
+                time=(
+                    nice_repr(timedelta(seconds=format_data["time"]), "noday")
+                    if self.config["cumtime"]
+                    else ""
+                ),
             )
         else:
             return mark_safe('<td class="problem-score-col"></td>')
 
     def display_participation_result(self, participation, show_final=False):

Check failure on line 143 in /home/runner/work/online-judge/online-judge/judge/contest_format/ioi.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/contest_format/ioi.py#L134-L143

             score = participation.score
             cumtime = participation.cumtime
         return format_html(
             '<td class="user-points">{points}<div class="solving-time">{cumtime}</div></td>',
             points=floatformat(score, -self.contest.points_precision),
-            cumtime=nice_repr(timedelta(seconds=cumtime), "noday")
-            if self.config["cumtime"]
-            else "",
+            cumtime=(
+                nice_repr(timedelta(seconds=cumtime), "noday")
+                if self.config["cumtime"]
+                else ""
+            ),
         )

Check failure on line 96 in /home/runner/work/online-judge/online-judge/judge/management/commands/render_pdf.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/management/commands/render_pdf.py#L83-L96

                 get_template("problem/raw.html")
                 .render(
                     {
                         "problem": problem,
                         "problem_name": problem_name,
-                        "description": problem.description
-                        if trans is None
-                        else trans.description,
+                        "description": (
+                            problem.description if trans is None else trans.description
+                        ),
                         "url": "",
                     }
                 )
                 .replace('"//', '"https://')
                 .replace("'//", "'https://")

Check failure on line 125 in /home/runner/work/online-judge/online-judge/judge/judgeapi.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/judgeapi.py#L110-L125

                 "submission-id": submission.id,
                 "problem-id": submission.problem.code,
                 "language": submission.language.key,
                 "source": submission.source.source,
                 "judge-id": judge_id,
-                "priority": BATCH_REJUDGE_PRIORITY
-                if batch_rejudge
-                else REJUDGE_PRIORITY
-                if rejudge
-                else priority,
+                "priority": (
+                    BATCH_REJUDGE_PRIORITY
+                    if batch_rejudge
+                    else REJUDGE_PRIORITY if rejudge else priority
+                ),
             }
         )
     except BaseException:
         logger.exception("Failed to send request to judge")
         Submission.objects.filter(id=submission.id).update(status="IE", result="IE")

Check failure on line 178 in /home/runner/work/online-judge/online-judge/judge/models/submission.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/models/submission.py#L165-L178

         except AttributeError:
             return
 
         contest_problem = contest.problem
         contest.points = round(
-            self.case_points / self.case_total * contest_problem.points
-            if self.case_total > 0
-            else 0,
+            (
+                self.case_points / self.case_total * contest_problem.points
+                if self.case_total > 0
+                else 0
+            ),
             3,
         )
         if not contest_problem.partial and contest.points != contest_problem.points:
             contest.points = 0
         contest.save()

Check failure on line 37 in /home/runner/work/online-judge/online-judge/judge/tasks/contest.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/tasks/contest.py#L22-L37

         for participation in participations.iterator():
             for contest_submission in participation.submissions.iterator():
                 submission = contest_submission.submission
                 contest_problem = contest_submission.problem
                 contest_submission.points = round(
-                    submission.case_points
-                    / submission.case_total
-                    * contest_problem.points
-                    if submission.case_total > 0
-                    else 0,
+                    (
+                        submission.case_points
+                        / submission.case_total
+                        * contest_problem.points
+                        if submission.case_total > 0
+                        else 0
+                    ),
                     3,
                 )
                 if (
                     not contest_problem.partial
                     and contest_submission.points != contest_problem.points

Check failure on line 25 in /home/runner/work/online-judge/online-judge/judge/ratings.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/ratings.py#L12-L25

 MEAN_INIT = 1400.0
 VAR_INIT = 250**2 * (BETA2 / 212**2)
 SD_INIT = sqrt(VAR_INIT)
 VALID_RANGE = MEAN_INIT - 20 * SD_INIT, MEAN_INIT + 20 * SD_INIT
 VAR_PER_CONTEST = 1219.047619 * (BETA2 / 212**2)
-VAR_LIM = (
-    sqrt(VAR_PER_CONTEST**2 + 4 * BETA2 * VAR_PER_CONTEST) - VAR_PER_CONTEST
-) / 2
+VAR_LIM = (sqrt(VAR_PER_CONTEST**2 + 4 * BETA2 * VAR_PER_CONTEST) - VAR_PER_CONTEST) / 2
 SD_LIM = sqrt(VAR_LIM)
 TANH_C = sqrt(3) / pi
 
 
 def tie_ranker(iterable, key=attrgetter("points")):

Check failure on line 616 in /home/runner/work/online-judge/online-judge/judge/models/profile.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/models/profile.py#L603-L616

         "email": user.email,
         "username": user.username,
         "mute": profile.mute,
         "first_name": user.first_name or None,
         "last_name": user.last_name or None,
-        "profile_image_url": profile.profile_image.url
-        if profile.profile_image
-        else None,
+        "profile_image_url": (
+            profile.profile_image.url if profile.profile_image else None
+        ),
         "display_rank": profile.display_rank,
         "rating": profile.rating,
     }
     res = {k: v for k, v in res.items() if v is not None}
     return res

Check failure on line 59 in /home/runner/work/online-judge/online-judge/judge/tasks/submission.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/tasks/submission.py#L46-L59

 
     with Progress(self, submissions.count(), stage=_("Modifying submissions")) as p:
         rescored = 0
         for submission in submissions.iterator():
             submission.points = round(
-                submission.case_points / submission.case_total * problem.points
-                if submission.case_total
-                else 0,
+                (
+                    submission.case_points / submission.case_total * problem.points
+                    if submission.case_total
+                    else 0
+                ),
                 1,
             )
             if not problem.partial and submission.points < problem.points:
                 submission.points = 0
             submission.save(update_fields=["points"])

Check failure on line 40 in /home/runner/work/online-judge/online-judge/judge/utils/pwned.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/utils/pwned.py#L29-L40

 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."""
-
 
 import hashlib
 import logging
 
 import requests

Check failure on line 80 in /home/runner/work/online-judge/online-judge/judge/utils/mathoid.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/utils/mathoid.py#L67-L80

                 self.mathoid_url,
                 data={
                     "q": reescape.sub(lambda m: "\\" + m.group(0), formula).encode(
                         "utf-8"
                     ),
-                    "type": "tex"
-                    if formula.startswith(r"\displaystyle")
-                    else "inline-tex",
+                    "type": (
+                        "tex" if formula.startswith(r"\displaystyle") else "inline-tex"
+                    ),
                 },
             )
             response.raise_for_status()
             data = response.json()
         except requests.ConnectionError:

Check failure on line 98 in /home/runner/work/online-judge/online-judge/judge/views/api/api_v1.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/api/api_v1.py#L77-L98

             "rating_ceiling": contest.rating_ceiling,
             "format": {
                 "name": contest.format_name,
                 "config": contest.format_config,
             },
-            "problems": [
-                {
-                    "points": int(problem.points),
-                    "partial": problem.partial,
-                    "name": problem.problem.name,
-                    "code": problem.problem.code,
-                }
-                for problem in problems
-            ]
-            if can_see_problems
-            else [],
+            "problems": (
+                [
+                    {
+                        "points": int(problem.points),
+                        "partial": problem.partial,
+                        "name": problem.problem.name,
+                        "code": problem.problem.code,
+                    }
+                    for problem in problems
+                ]
+                if can_see_problems
+                else []
+            ),
             "rankings": [
                 {
                     "user": participation.username,
                     "points": participation.score,
                     "cumtime": participation.cumtime,

Check failure on line 74 in /home/runner/work/online-judge/online-judge/judge/views/blog.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/blog.py#L61-L74

 
         context["current_contests"] = visible_contests.filter(
             start_time__lte=now, end_time__gt=now
         )
         context["future_contests"] = visible_contests.filter(start_time__gt=now)
-        context[
-            "recent_organizations"
-        ] = OrganizationProfile.get_most_recent_organizations(self.request.profile)
+        context["recent_organizations"] = (
+            OrganizationProfile.get_most_recent_organizations(self.request.profile)
+        )
 
         profile_queryset = Profile.objects
         if self.request.organization:
             profile_queryset = self.request.organization.members
         context["top_rated"] = (

Check failure on line 62 in /home/runner/work/online-judge/online-judge/judge/views/ranked_submission.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/ranked_submission.py#L49-L62

                 WHERE sub.problem_id = %s {constraint}
                 GROUP BY sub.user_id
             """.format(
                 points=points, contest_join=contest_join, constraint=constraint
             ),
-            params=[self.problem.id, self.contest.id] * 3
-            if self.in_contest
-            else [self.problem.id] * 3,
+            params=(
+                [self.problem.id, self.contest.id] * 3
+                if self.in_contest
+                else [self.problem.id] * 3
+            ),
             alias="best_subs",
             join_fields=[("id", "id")],
             related_model=Submission,
         )
 

Check failure on line 208 in /home/runner/work/online-judge/online-judge/judge/views/test_formatter/test_formatter.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/test_formatter/test_formatter.py#L199-L208

     def post(self, request):
         file_path = request.POST.get("file_path")
 
         with open(file_path, "rb") as zip_file:
             response = HttpResponse(zip_file.read(), content_type="application/zip")
-            response[
-                "Content-Disposition"
-            ] = f"attachment; filename={os.path.basename(file_path)}"
+            response["Content-Disposition"] = (
+                f"attachment; filename={os.path.basename(file_path)}"
+            )
             return response

Check failure on line 104 in /home/runner/work/online-judge/online-judge/judge/views/widgets.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/widgets.py#L96-L104

             lat, long = float(request.GET["lat"]), float(request.GET["long"])
         except (ValueError, KeyError):
             return HttpResponse(
                 _("Bad latitude or longitude"), content_type="text/plain", status=404
             )
-        return {"askgeo": self.askgeo, "geonames": self.geonames,}.get(
+        return {
+            "askgeo": self.askgeo,
+            "geonames": self.geonames,
+        }.get(
             backend, self.default
         )(lat, long)

Check failure on line 31 in /home/runner/work/online-judge/online-judge/judge/widgets/checkbox.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/widgets/checkbox.py#L19-L31

             template.render(
                 {
                     "original_widget": original,
                     "select_all_id": select_all_id,
                     "select_all_name": select_all_name,
-                    "all_selected": all(choice[0] in value for choice in self.choices)
-                    if value
-                    else False,
+                    "all_selected": (
+                        all(choice[0] in value for choice in self.choices)
+                        if value
+                        else False
+                    ),
                     "empty": not self.choices,
                 }
             )
         )

Check failure on line 57 in /home/runner/work/online-judge/online-judge/judge/widgets/mixins.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/widgets/mixins.py#L45-L57

                 media = super().media
                 template = self.__templates[self.compress_css, self.compress_js]
                 result = html.fromstring(template.render(Context({"media": media})))
 
                 return forms.Media(
-                    css={"all": [result.find(".//link").get("href")]}
-                    if self.compress_css
-                    else media._css,
-                    js=[result.find(".//script").get("src")]
-                    if self.compress_js
-                    else media._js,
+                    css=(
+                        {"all": [result.find(".//link").get("href")]}
+                        if self.compress_css
+                        else media._css
+                    ),
+                    js=(
+                        [result.find(".//script").get("src")]
+                        if self.compress_js
+                        else media._js
+                    ),
                 )

Check failure on line 408 in /home/runner/work/online-judge/online-judge/judge/views/problem.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/problem.py#L395-L408

                     get_template("problem/raw.html")
                     .render(
                         {
                             "problem": problem,
                             "problem_name": problem_name,
-                            "description": problem.description
-                            if trans is None
-                            else trans.description,
+                            "description": (
+                                problem.description
+                                if trans is None
+                                else trans.description
+                            ),
                             "url": request.build_absolute_uri(),
                         }
                     )
                     .replace('"//', '"https://')
                     .replace("'//", "'https://")

Check failure on line 532 in /home/runner/work/online-judge/online-judge/judge/views/problem.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/problem.py#L519-L532

                 )
         elif sort_key == "type":
             if self.show_types:
                 queryset = list(queryset)
                 queryset.sort(
-                    key=lambda problem: problem.types_list[0]
-                    if problem.types_list
-                    else "",
+                    key=lambda problem: (
+                        problem.types_list[0] if problem.types_list else ""
+                    ),
                     reverse=self.order.startswith("-"),
                 )
         return queryset
 
     @cached_property

Check failure on line 1214 in /home/runner/work/online-judge/online-judge/judge/views/problem.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/problem.py#L1201-L1214

             "submission_limit": submission_limit,
             "submissions_left": submissions_left,
             "ACE_URL": settings.ACE_URL,
             "default_lang": default_lang,
             "problem_id": problem.id,
-            "output_only": problem.data_files.output_only
-            if hasattr(problem, "data_files")
-            else False,
+            "output_only": (
+                problem.data_files.output_only
+                if hasattr(problem, "data_files")
+                else False
+            ),
             "next_valid_submit_time": next_valid_submit_time,
         },
     )
 
 

Check failure on line 395 in /home/runner/work/online-judge/online-judge/judge/views/contests.py

See this annotation in the file changed.

@github-actions github-actions / Black

/home/runner/work/online-judge/online-judge/judge/views/contests.py#L380-L395

 
     def get_context_data(self, **kwargs):
         context = super(ContestMixin, self).get_context_data(**kwargs)
         if self.request.user.is_authenticated:
             try:
-                context[
-                    "live_participation"
-                ] = self.request.profile.contest_history.get(
-                    contest=self.object,
-                    virtual=ContestParticipation.LIVE,
+                context["live_participation"] = (
+                    self.request.profile.contest_history.get(
+                        contest=self.object,
+                        virtual=ContestParticipation.LIVE,
+                    )
                 )
             except ContestParticipation.DoesNotExist:
                 context["live_participation"] = None
                 context["has_joined"] = False
             else: