feat: more strict models
This commit is contained in:
parent
3f0fdd816b
commit
6795290d7c
|
@ -17,7 +17,7 @@ repos:
|
||||||
- id: yamlfmt
|
- id: yamlfmt
|
||||||
exclude: '^tests/'
|
exclude: '^tests/'
|
||||||
- repo: https://github.com/pdm-project/pdm
|
- repo: https://github.com/pdm-project/pdm
|
||||||
rev: 2.19.2
|
rev: 2.25.9
|
||||||
hooks:
|
hooks:
|
||||||
- id: pdm-lock-check
|
- id: pdm-lock-check
|
||||||
- repo: https://github.com/pre-commit/mirrors-mypy
|
- repo: https://github.com/pre-commit/mirrors-mypy
|
||||||
|
|
|
@ -4,14 +4,7 @@ from enum import Enum
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any, Dict, List, Optional, Type
|
from typing import Any, Dict, List, Optional, Type
|
||||||
|
|
||||||
from pydantic import (
|
from pydantic import AliasChoices, ConfigDict, Field, field_validator, model_validator
|
||||||
AliasChoices,
|
|
||||||
BaseModel,
|
|
||||||
ConfigDict,
|
|
||||||
Field,
|
|
||||||
field_validator,
|
|
||||||
model_validator,
|
|
||||||
)
|
|
||||||
|
|
||||||
from joj3_config_generator.models.common import Memory, StrictBaseModel, Time
|
from joj3_config_generator.models.common import Memory, StrictBaseModel, Time
|
||||||
from joj3_config_generator.models.const import (
|
from joj3_config_generator.models.const import (
|
||||||
|
@ -25,7 +18,7 @@ from joj3_config_generator.models.const import (
|
||||||
from joj3_config_generator.models.repo import Groups
|
from joj3_config_generator.models.repo import Groups
|
||||||
|
|
||||||
|
|
||||||
class ParserResultDetail(BaseModel):
|
class ParserResultDetail(StrictBaseModel):
|
||||||
cpu_time: bool = Field(
|
cpu_time: bool = Field(
|
||||||
True, validation_alias=AliasChoices("cpu-time", "cpu_time", "cpu")
|
True, validation_alias=AliasChoices("cpu-time", "cpu_time", "cpu")
|
||||||
) # Display CPU time
|
) # Display CPU time
|
||||||
|
@ -48,17 +41,17 @@ class ParserResultDetail(BaseModel):
|
||||||
) # Max output length of each file
|
) # Max output length of each file
|
||||||
|
|
||||||
|
|
||||||
class ParserFile(BaseModel):
|
class ParserFile(StrictBaseModel):
|
||||||
name: str = ""
|
name: str = ""
|
||||||
|
|
||||||
|
|
||||||
class ParserLog(BaseModel):
|
class ParserLog(StrictBaseModel):
|
||||||
filename: str
|
filename: str
|
||||||
msg: str = ""
|
msg: str = ""
|
||||||
level: str = ""
|
level: str = ""
|
||||||
|
|
||||||
|
|
||||||
class ParserDummy(BaseModel):
|
class ParserDummy(StrictBaseModel):
|
||||||
comment: str = ""
|
comment: str = ""
|
||||||
score: int = 0
|
score: int = 0
|
||||||
force_quit: bool = Field(
|
force_quit: bool = Field(
|
||||||
|
@ -66,7 +59,7 @@ class ParserDummy(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ParserResultStatus(BaseModel):
|
class ParserResultStatus(StrictBaseModel):
|
||||||
comment: str = ""
|
comment: str = ""
|
||||||
score: int = 0
|
score: int = 0
|
||||||
force_quit: bool = Field(
|
force_quit: bool = Field(
|
||||||
|
@ -74,13 +67,13 @@ class ParserResultStatus(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ParserKeyword(BaseModel):
|
class ParserKeyword(StrictBaseModel):
|
||||||
score: int = 0
|
score: int = 0
|
||||||
keyword: List[str] = []
|
keyword: List[str] = []
|
||||||
weight: List[int] = []
|
weight: List[int] = []
|
||||||
|
|
||||||
|
|
||||||
class ParserDiffOutputs(BaseModel):
|
class ParserDiffOutputs(StrictBaseModel):
|
||||||
score: int = 0
|
score: int = 0
|
||||||
ignore_spaces: bool = Field(
|
ignore_spaces: bool = Field(
|
||||||
True, validation_alias=AliasChoices("ignore-spaces", "ignore_spaces")
|
True, validation_alias=AliasChoices("ignore-spaces", "ignore_spaces")
|
||||||
|
@ -98,7 +91,7 @@ class ParserDiffOutputs(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ParserDiff(BaseModel):
|
class ParserDiff(StrictBaseModel):
|
||||||
score: int = DEFAULT_CASE_SCORE
|
score: int = DEFAULT_CASE_SCORE
|
||||||
ignore_spaces: bool = Field(
|
ignore_spaces: bool = Field(
|
||||||
True, validation_alias=AliasChoices("ignore-spaces", "ignore_spaces")
|
True, validation_alias=AliasChoices("ignore-spaces", "ignore_spaces")
|
||||||
|
@ -133,7 +126,7 @@ class ParserDiff(BaseModel):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
class StageFiles(BaseModel):
|
class StageFiles(StrictBaseModel):
|
||||||
import_: List[str] = Field([], validation_alias="import")
|
import_: List[str] = Field([], validation_alias="import")
|
||||||
export: List[str] = []
|
export: List[str] = []
|
||||||
import_map: Dict[str, str] = Field(
|
import_map: Dict[str, str] = Field(
|
||||||
|
@ -141,7 +134,7 @@ class StageFiles(BaseModel):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class Limit(BaseModel):
|
class Limit(StrictBaseModel):
|
||||||
mem: int = DEFAULT_MEMORY_LIMIT
|
mem: int = DEFAULT_MEMORY_LIMIT
|
||||||
cpu: int = DEFAULT_CPU_LIMIT
|
cpu: int = DEFAULT_CPU_LIMIT
|
||||||
time: int = 0
|
time: int = 0
|
||||||
|
|
|
@ -70,7 +70,6 @@ disallow_untyped_defs = true
|
||||||
[tool.pydantic-mypy]
|
[tool.pydantic-mypy]
|
||||||
init_forbid_extra = true
|
init_forbid_extra = true
|
||||||
init_typed = true
|
init_typed = true
|
||||||
warn_required_dynamic_aliases = true
|
|
||||||
warn_untyped_fields = true
|
warn_untyped_fields = true
|
||||||
|
|
||||||
[tool.setuptools_scm]
|
[tool.setuptools_scm]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user