Skip to content

Commit

Permalink
Update to ruff 0.9, fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
inducer committed Jan 11, 2025
1 parent 665900e commit 2547d52
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 59 deletions.
5 changes: 3 additions & 2 deletions course/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import os
import re
import sys
from dataclasses import dataclass
from typing import cast
from xml.etree.ElementTree import Element, tostring

Expand Down Expand Up @@ -1195,9 +1196,9 @@ def unknown_decl(self, data):
self.out_file.write(f"<![{data}]>")


@dataclass
class PreserveFragment:
def __init__(self, s: str) -> None:
self.s = s
s: str


class LinkFixerTreeprocessor(Treeprocessor):
Expand Down
8 changes: 4 additions & 4 deletions course/grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"""

import re
from dataclasses import dataclass
from decimal import Decimal
from typing import (
TYPE_CHECKING,
Expand Down Expand Up @@ -210,11 +211,10 @@ def view_grading_opportunity_list(pctx):

# {{{ teacher grade book

@dataclass
class GradeInfo:
def __init__(self, opportunity: GradingOpportunity,
grade_state_machine: GradeStateMachine) -> None:
self.opportunity = opportunity
self.grade_state_machine = grade_state_machine
opportunity: GradingOpportunity
grade_state_machine: GradeStateMachine


def get_grade_table(course: Course) -> tuple[
Expand Down
33 changes: 12 additions & 21 deletions course/page/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

from abc import ABC, abstractmethod
from collections.abc import Callable, Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any

import django.forms as forms
Expand Down Expand Up @@ -97,6 +98,7 @@
"""


@dataclass
class PageContext:
"""
.. attribute:: course
Expand All @@ -113,24 +115,13 @@ class PageContext:
which is used internally by the flow views.
"""

def __init__(
self,
course: Course,
repo: Repo_ish,
commit_sha: bytes,
flow_session: FlowSession,
in_sandbox: bool = False,
page_uri: str | None = None,
request: django.http.HttpRequest | None = None,
) -> None:

self.course = course
self.repo = repo
self.commit_sha = commit_sha
self.flow_session = flow_session
self.in_sandbox = in_sandbox
self.page_uri = page_uri
self.request = request
course: Course
repo: Repo_ish
commit_sha: bytes
flow_session: FlowSession
in_sandbox: bool = False
page_uri: str | None = None
request: django.http.HttpRequest | None = None


class PageBehavior:
Expand Down Expand Up @@ -194,11 +185,11 @@ def round_point_count_to_quarters(
return int(value)

import math
_atol = atol * 4
actual_atol = atol * 4
v = value * 4
if abs(v - math.floor(v)) < _atol:
if abs(v - math.floor(v)) < actual_atol:
v = math.floor(v)
elif abs(v - math.ceil(v)) < _atol:
elif abs(v - math.ceil(v)) < actual_atol:
v = math.ceil(v)
else:
return value
Expand Down
13 changes: 7 additions & 6 deletions course/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import re
import sys
from collections.abc import Sequence
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Literal, TypeAlias

import dulwich.objects
Expand Down Expand Up @@ -226,10 +227,10 @@ def validate_struct(
# }}}


@dataclass
class ValidationWarning:
def __init__(self, location: str | None, text: str) -> None:
self.location = location
self.text = text
location: str | None
text: str


class ValidationContext:
Expand Down Expand Up @@ -1588,10 +1589,10 @@ def tree(self):
return FileSystemFakeRepoTree(self.root)


@dataclass
class FileSystemFakeRepoTreeEntry: # pragma: no cover
def __init__(self, path: bytes, mode: int) -> None:
self.path = path
self.mode = mode
path: bytes
mode: int


class FileSystemFakeRepoTree: # pragma: no cover
Expand Down
40 changes: 20 additions & 20 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ urllib3 = "^2.3.0"

[tool.poetry.dev-dependencies]
factory_boy = "^3.3.1"
ruff = "^0.8"
ruff = "^0"

django-stubs = { version ="5.1.*", extras = ["compatible-mypy"] }

Expand Down
2 changes: 1 addition & 1 deletion tests/base_test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,7 +1639,7 @@ def get_page_visits(cls, course_identifier=None,
flow_session_id=None, page_ordinal=None, page_id=None,
**kwargs):
query_kwargs = {}
if kwargs.get("answer_visit", False):
if kwargs.get("answer_visit"):
query_kwargs.update({"answer__isnull": False})
flow_params = cls.get_flow_params(course_identifier, flow_session_id)
query_kwargs.update({"flow_session_id": flow_params["flow_session_id"]})
Expand Down
5 changes: 3 additions & 2 deletions tests/test_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import stat
import unittest
from copy import deepcopy
from dataclasses import dataclass
from zoneinfo import ZoneInfo

import pytest
Expand Down Expand Up @@ -334,9 +335,9 @@ def setUp(self):
def test_file_uses_tab_in_indentation(self):
fake_yaml_bytestream = b"\tabcd\n"

@dataclass
class _Blob:
def __init__(self):
self.data = fake_yaml_bytestream
data: bytes = fake_yaml_bytestream

with mock.patch("course.content.get_repo_blob") as mock_get_repo_blob:
mock_get_repo_blob.return_value = _Blob()
Expand Down
5 changes: 3 additions & 2 deletions tests/test_grades/test_grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import datetime
import io
import unittest
from dataclasses import dataclass

import pytest
from django.test import Client, TestCase
Expand Down Expand Up @@ -659,9 +660,9 @@ def test(self):
fake_task_id = "abcdef123"


@dataclass
class MockAsyncRes:
def __init__(self):
self.id = fake_task_id
id: str = fake_task_id


class ViewGradesByOpportunityTest(GradesTestMixin, TestCase):
Expand Down

0 comments on commit 2547d52

Please sign in to comment.