Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove pydantic support #22

Merged
merged 2 commits into from
Sep 10, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 0 additions & 68 deletions rusty_results/prelude.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
from typing import cast, TypeVar, Union, Callable, Generic, Iterator, Tuple, Dict, Any, Optional
from rusty_results.exceptions import UnwrapException, EarlyReturnException

try:
from pydantic.fields import ModelField
except ImportError: # pragma: no cover
...

# base inner type generic
T = TypeVar('T')
Expand Down Expand Up @@ -278,70 +274,6 @@ def __invert__(self) -> T:
"""
return self.early_return()

@classmethod
def __get_validators__(cls):
yield cls.__validate

@classmethod
def __validate(cls, value: Union["Some", "Empty", Dict], field: "ModelField"):
if isinstance(value, Some):
return cls.__validate_some(value, field)
elif isinstance(value, Empty):
return cls.__validate_empty(value, field)
elif isinstance(value, dict):
return cls.__validate_dict(value, field)

raise TypeError("Unable to validate Option") # pragma: no cover

@classmethod
def __validate_some(cls, value: "Some", field: "ModelField"):
import pydantic

if not field.sub_fields:
raise TypeError("No subfields found for Some")

field_value = field.sub_fields[0]
valid_value, error = field_value.validate(value.Some, {}, loc="")
if error:
# ignore type since it do not come from a base model
raise pydantic.ValidationError((error, ), Some) # type: ignore

return Some(valid_value)

@classmethod
def __validate_empty(cls, _: "Empty", field: "ModelField"):
if field.sub_fields:
raise TypeError("Empty value cannot be bound to external types")

return Empty()

@classmethod
def __validate_dict(cls, value: Dict, field: "ModelField"):
import pydantic

if value == {}:
return Empty()

if len(value) != 1:
raise TypeError(
"Extra object parameters found, Option can have strictly 0 (Empty) or 1 Value (Some)",
)

inner_value = value.get("Some")
if inner_value is None:
raise TypeError("Non Empty Option do not have a proper Value")

if not field.sub_fields:
raise TypeError("Cannot check Option pydantic subfields validations") # pragma: no cover

field_value = field.sub_fields[0]
valid_value, error = field_value.validate(value["Some"], {}, loc="")
if error:
# ignore type since it do not come from a base model
raise pydantic.ValidationError(error, Option) # type: ignore # pragma: no cover

return Some(valid_value)


@dataclass(eq=True, frozen=True)
class Some(OptionProtocol[T]):
Expand Down
Empty file.
41 changes: 0 additions & 41 deletions rusty_results/tests/serde/test_option_empty.py

This file was deleted.

49 changes: 0 additions & 49 deletions rusty_results/tests/serde/test_option_some.py

This file was deleted.

49 changes: 0 additions & 49 deletions rusty_results/tests/serde/test_result_err.py

This file was deleted.

48 changes: 0 additions & 48 deletions rusty_results/tests/serde/test_result_ok.py

This file was deleted.

3 changes: 0 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,5 @@
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
extras_require={
"pydantic": ["pydantic"]
},
python_requires='>=3.7'
)
Loading