Skip to content

Commit

Permalink
Small changes required by older python versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pszpetkowski committed Jul 29, 2023
1 parent ea76eb5 commit 33f61c9
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/hidori_core/schema/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ class Schema:
_internals_fields: Dict[str, Field]

def __init_subclass__(cls) -> None:
# old pythons unfortunately
cls.__annotations__.pop("_internals_fields", "")

for name in cls.__annotations__.keys():
if name.startswith("_internals"):
raise schema_errors.FieldNameNotAllowed(
Expand Down
6 changes: 6 additions & 0 deletions tests/test_core/test_schema/test_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@ def test_schema_with_default_field_setup_and_validation(required, exc):
[(True, schema_errors.ValidationError), (False, schema_errors.SkipFieldError)],
)
def test_dict_field_setup_and_validation(dict_type, required, exc):
# old pythons unfortunately
try:
dict_type[str, str]
except TypeError:
return

assert schema_fields.Dictionary.from_annotation(Any, required) is None
assert schema_fields.Dictionary.from_annotation(int, required) is None
assert schema_fields.Dictionary.from_annotation(str, required) is None
Expand Down
10 changes: 5 additions & 5 deletions tests/test_core/test_schema/test_modifiers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Literal
from typing import Any, Dict, List, Literal, Optional

import pytest

Expand All @@ -8,14 +8,14 @@


class SimpleModifier(SchemaModifier):
def __init__(self, data_conditions: list[DataCondtion] | None = None) -> None:
def __init__(self, data_conditions: Optional[List[DataCondtion]] = None) -> None:
self.data_conditions = data_conditions or []

def process_schema(self, annotations: dict[str, Any]) -> None:
def process_schema(self, annotations: Dict[str, Any]) -> None:
if "throw_error" in annotations:
raise schema_errors.ModifierError()

def apply_to_schema(self, schema: Schema, data: dict[str, Any]) -> None:
def apply_to_schema(self, schema: Schema, data: Dict[str, Any]) -> None:
if data["state"] == "modify":
setattr(schema._internals_fields["a"], "modified", True)
setattr(schema._internals_fields["b"], "modified", True)
Expand All @@ -36,7 +36,7 @@ class SimpleSchema(Schema):

class OptionalSchema(Schema):
a: str
b: str | None
b: Optional[str]


def test_simple_modifier_throw_error_on_schema_processing():
Expand Down
File renamed without changes.

0 comments on commit 33f61c9

Please sign in to comment.