Skip to content

Commit

Permalink
Refactor consts.py to use NullModule class for blocked modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Kamil Rybacki committed Jul 16, 2024
1 parent 5c89c75 commit 50fe1e0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 11 deletions.
6 changes: 5 additions & 1 deletion phaistos/consts.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ from types import ModuleType

class NullModule(ModuleType):
LOCK: ClassVar[bool]
def __getattr__(self, *args, **kwargs): ...
def __getattr__(self, *args, **kwargs):
"""
This method is called when the module is accessed,
to prevent the module from being accessed.
"""

ALLOWED_COLLECTION_TYPES: set
COLLECTION_TYPE_REGEX: str
Expand Down
2 changes: 2 additions & 0 deletions phaistos/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import datetime
import dataclasses

class ForbiddenModuleUseInValidator(ImportError): ...

class SchemaLoadingException(Exception): ...

class IncorrectFieldTypeError(ValueError): ...

@dataclasses.dataclass(kw_only=True)
class FieldValidationErrorInfo:
name: str
message: str
Expand Down
7 changes: 2 additions & 5 deletions phaistos/schema.pyi
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import dataclasses
from typing import Any, ClassVar

import pydantic._internal._decorators
Expand All @@ -19,12 +18,12 @@ class TranspiledSchema(pydantic.main.BaseModel):
def compile(cls, model_data: TranspiledModelData) -> type[TranspiledSchema]: ...
@classmethod
def _rename_schema(cls, schema: type[TranspiledSchema], name: str) -> None: ...
def __init__(self, **data: Any) -> None:
def __init__(self, **data) -> None:
"""
A modified version of the Pydantic BaseModel __init__ method that
passed the context to the validator.
"""
def model_post_init(self: pydantic.main.BaseModel, __context: Any) -> None:
def model_post_init(self: pydantic.main.BaseModel, __context) -> None:
"""This function is meant to behave like a BaseModel method to initialise private attributes.
It takes context as an argument since that's what pydantic-core passes when calling it.
Expand Down Expand Up @@ -54,5 +53,3 @@ class SchemaInstancesFactory:
ValidationResults: The validation results, including the schema, errors, and data.
"""
def build(self, data: dict[str, Any]) -> TranspiledSchema | None: ...
def __init__(self) -> None: ...
def __eq__(self, other) -> bool: ...
2 changes: 0 additions & 2 deletions phaistos/transpiler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ class Transpiler:
def supress_logging(cls) -> None: ...
@classmethod
def enable_logging(cls) -> None: ...
def __init__(self) -> None: ...
def __eq__(self, other) -> bool: ...
3 changes: 0 additions & 3 deletions phaistos/typings.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,3 @@ class ValidationResults:
schema: dict
errors: list[FieldValidationErrorInfo]
data: dict
__dataclass_params__: typing.ClassVar[dataclasses._DataclassParams]
__dataclass_fields__: typing.ClassVar[dict]
__match_args__: typing.ClassVar[tuple]

0 comments on commit 50fe1e0

Please sign in to comment.