Skip to content

Commit

Permalink
more final
Browse files Browse the repository at this point in the history
  • Loading branch information
mzuenni committed Feb 11, 2025
1 parent 8d27d20 commit 0a40d22
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 23 deletions.
24 changes: 12 additions & 12 deletions bin/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from collections.abc import Callable
from colorama import Fore, Style
from pathlib import Path, PurePosixPath
from typing import overload
from typing import Final, overload

import config
import parallel
Expand Down Expand Up @@ -40,7 +40,7 @@ def assert_type(name, obj, types, path=None):
)


UNIQUE_TESTCASE_KEYS = [
UNIQUE_TESTCASE_KEYS: Final = [
"copy",
"generate",
"retries",
Expand Down Expand Up @@ -88,8 +88,8 @@ def resolve_path(path, *, allow_absolute, allow_relative):
# - SolutionInvocation
# - VisualizerInvocation
class Invocation:
SEED_REGEX = re.compile(r"\{seed(:[0-9]+)?\}")
NAME_REGEX = re.compile(r"\{name\}")
SEED_REGEX: Final = re.compile(r"\{seed(:[0-9]+)?\}")
NAME_REGEX: Final = re.compile(r"\{name\}")

# `string` is the name of the submission (relative to generators/ or absolute from the problem root) with command line arguments.
# A direct path may also be given.
Expand Down Expand Up @@ -318,7 +318,7 @@ def __init__(self, generator_config):
super().__init__(generator_config.problem, default_solution_path(generator_config))


KNOWN_TESTCASE_KEYS = [
KNOWN_TESTCASE_KEYS: Final = [
"type",
"generate",
"copy",
Expand All @@ -328,8 +328,8 @@ def __init__(self, generator_config):
"retries",
"count",
] + [e[1:] for e in config.KNOWN_TEXT_DATA_EXTENSIONS]
RESERVED_TESTCASE_KEYS = ["data", "testdata.yaml", "include"]
KNOWN_DIRECTORY_KEYS = [
RESERVED_TESTCASE_KEYS: Final = ["data", "testdata.yaml", "include"]
KNOWN_DIRECTORY_KEYS: Final = [
"type",
"data",
"testdata.yaml",
Expand All @@ -339,9 +339,9 @@ def __init__(self, generator_config):
"random_salt",
"retries",
]
RESERVED_DIRECTORY_KEYS = ["command"]
KNOWN_ROOT_KEYS = ["generators", "parallel"]
DEPRECATED_ROOT_KEYS = ["gitignore_generated"]
RESERVED_DIRECTORY_KEYS: Final = ["command"]
KNOWN_ROOT_KEYS: Final = ["generators", "parallel"]
DEPRECATED_ROOT_KEYS: Final = ["gitignore_generated"]


# Holds all inheritable configuration options. Currently:
Expand Down Expand Up @@ -372,7 +372,7 @@ def parse_random_salt(p, x, path):
return ""
return x

INHERITABLE_KEYS = [
INHERITABLE_KEYS: Final = [
# True: use an AC submission by default when the solution: key is not present.
("solution", True, parse_solution),
("visualizer", None, parse_visualizer),
Expand Down Expand Up @@ -1413,7 +1413,7 @@ def parse_generators(generators_yaml):
return generators

# Only used at the root directory level.
ROOT_KEYS = [
ROOT_KEYS: Final = [
("generators", dict[Path, list[Path]](), parse_generators),
]

Expand Down
4 changes: 2 additions & 2 deletions bin/interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import subprocess
import sys
import threading
from typing import Literal, Optional, TYPE_CHECKING
from typing import Final, Literal, Optional, TYPE_CHECKING

import config
from util import *
Expand All @@ -13,7 +13,7 @@
if TYPE_CHECKING:
from run import Run

BUFFER_SIZE = 2**20
BUFFER_SIZE: Final = 2**20


# Return a ExecResult object amended with verdict.
Expand Down
6 changes: 3 additions & 3 deletions bin/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from collections.abc import Callable
from pathlib import Path
from typing import Any, Literal, Optional, TYPE_CHECKING
from typing import Any, Final, Literal, Optional, TYPE_CHECKING

if TYPE_CHECKING: # Prevent circular import: https://stackoverflow.com/a/39757388
from program import Program
Expand Down Expand Up @@ -155,8 +155,8 @@ def is_legacy(self):

# A problem.
class Problem:
_SHORTNAME_REGEX_STRING = "^[a-z0-9]+$"
_SHORTNAME_REGEX = re.compile(_SHORTNAME_REGEX_STRING)
_SHORTNAME_REGEX_STRING: Final = "^[a-z0-9]+$"
_SHORTNAME_REGEX: Final = re.compile(_SHORTNAME_REGEX_STRING)

def __init__(self, path: Path, tmpdir: Path, label: Optional[str] = None):
# The problem name/shortname, which is the name of the directory and used as a display name.
Expand Down
6 changes: 3 additions & 3 deletions bin/program.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import stat
import subprocess
import threading
from typing import TYPE_CHECKING
from typing import Final, TYPE_CHECKING

from colorama import Fore

Expand All @@ -12,7 +12,7 @@
if TYPE_CHECKING: # Prevent circular import: https://stackoverflow.com/a/39757388
from problem import Problem

EXTRA_LANGUAGES = """
EXTRA_LANGUAGES: Final = """
checktestdata:
name: 'Checktestdata'
priority: 1
Expand All @@ -33,7 +33,7 @@
run: '{run}'
"""

SANITIZER_FLAGS = """
SANITIZER_FLAGS: Final = """
cpp:
compile: -fsanitize=undefined,address
"""
Expand Down
7 changes: 4 additions & 3 deletions bin/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import testcase
from util import *
from enum import Enum
from typing import Final
import re


Expand Down Expand Up @@ -78,7 +79,7 @@ class Validator(program.Program):
ExecResult.status == ExecStatus.REJECTED if the validator rejected.
"""

FORMAT_VALIDATOR_LANGUAGES = ["checktestdata", "viva"]
FORMAT_VALIDATOR_LANGUAGES: Final = ["checktestdata", "viva"]

def __repr__(self):
return type(self).__name__ + ": " + str(self.path)
Expand Down Expand Up @@ -378,8 +379,8 @@ def run(


# Checks if byte is printable or whitespace
INVALID_BYTES_WITH_OTHER = re.compile(b"[^\t\r\v\f\n\x20-\x7e]")
INVALID_BYTES = re.compile(b"[^\n\x20-\x7e]")
INVALID_BYTES_WITH_OTHER: Final = re.compile(b"[^\t\r\v\f\n\x20-\x7e]")
INVALID_BYTES: Final = re.compile(b"[^\n\x20-\x7e]")


def _has_invalid_byte(bytes, *, other_whitespaces=False):
Expand Down

0 comments on commit 0a40d22

Please sign in to comment.