Skip to content

Commit

Permalink
Fix pre-commit to work. (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
NowanIlfideme authored Mar 29, 2023
1 parent f8d65b9 commit 54ff4ba
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 28 deletions.
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Configuration for flake8. For some reason, they stubbornly avoid `pyproject.toml` support.

[flake8]
exclude =
exclude =
*
include =
include =
pydantic_yaml
max-line-length = 88
max-doc-length = 88
Expand Down
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ repos:
hooks:
- id: mypy
pass_filenames: false
args: [--config-file, pyproject.toml, --ignore-missing-imports]
args:
[
--config-file,
pyproject.toml,
--ignore-missing-imports,
--install-types,
--non-interactive,
]
# SEE: https://pre-commit.com/#repository-local-hooks
# - repo: local
# hooks:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ from pydantic_yaml import YamlStrEnum, YamlModel

class MyEnum(YamlStrEnum):
"""This is a custom enumeration that is YAML-safe."""

a = "a"
b = "b"

class InnerModel(BaseModel):
"""This is a normal pydantic model that can be used as an inner class."""

fld: float = 1.0

class MyModel(YamlModel):
"""This is our custom class, with a `.yaml()` method.
The `parse_raw()` and `parse_file()` methods are also updated to be able to
handle `content_type='application/yaml'`, `protocol="yaml"` and file names
ending with `.yml`/`.yaml`
Expand Down Expand Up @@ -141,7 +141,7 @@ class A(VersionedYamlModel):

class B(VersionedYamlModel):
"""Model with a maximum version set."""

foo: str = "bar"

class Config:
Expand Down
8 changes: 4 additions & 4 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ from pydantic_yaml import YamlStrEnum, YamlModel

class MyEnum(YamlStrEnum):
"""This is a custom enumeration that is YAML-safe."""

a = "a"
b = "b"

class InnerModel(BaseModel):
"""This is a normal pydantic model that can be used as an inner class."""

fld: float = 1.0

class MyModel(YamlModel):
"""This is our custom class, with a `.yaml()` method.
The `parse_raw()` and `parse_file()` methods are also updated to be able to
handle `content_type='application/yaml'`, `protocol="yaml"` and file names
ending with `.yml`/`.yaml`
Expand Down Expand Up @@ -129,7 +129,7 @@ class A(VersionedYamlModel):

class B(VersionedYamlModel):
"""Model with a maximum version set."""

foo: str = "bar"

class Config:
Expand Down
7 changes: 2 additions & 5 deletions src/pydantic_yaml/compat/yaml_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
__yaml_lib__ = "pyyaml"
except ImportError:
raise ImportError(
"Could not import ruamel.yaml or pyyaml, "
"please install at least one of them."
"Could not import ruamel.yaml or pyyaml, " "please install at least one of them."
)

dumper_classes = []
Expand Down Expand Up @@ -60,9 +59,7 @@ def yaml_safe_load(stream) -> Any:
return ruamel_obj.load(stream)


def yaml_safe_dump(
data: Any, stream=None, *, sort_keys: bool = False, **kwds
) -> Optional[Any]:
def yaml_safe_dump(data: Any, stream=None, *, sort_keys: bool = False, **kwds) -> Optional[Any]:
"""Wrapper around YAML library dumper.
Parameters
Expand Down
8 changes: 2 additions & 6 deletions src/pydantic_yaml/ext/versioned_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,7 @@ def __init_subclass__(cls) -> None:
# Check ranges
min_, max_ = _get_minmax_robust(cls)
if (min_ is not None) and (max_ is not None) and (min_ > max_):
raise ValueError(
f"Minimum version higher than maximum: {min_!r} > {max_!r}"
)
raise ValueError(f"Minimum version higher than maximum: {min_!r} > {max_!r}")

# Check the default value of the "version" field
fld = cls.__fields__["version"]
Expand All @@ -98,9 +96,7 @@ def __init_subclass__(cls) -> None:
)

if not issubclass(fld.type_, SemVer):
raise TypeError(
f"Field type for `version` must be SemVer, got {fld.type_!r}"
)
raise TypeError(f"Field type for `version` must be SemVer, got {fld.type_!r}")

@validator("version", always=True)
def _check_semver(cls, v):
Expand Down
8 changes: 2 additions & 6 deletions src/pydantic_yaml/mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,7 @@ def parse_raw(
cfg = cast(YamlModelMixinConfig, cls.__config__)
obj = cfg.yaml_loads(b)
except RecursionError as e:
raise ValueError(
"YAML files with recursive references are unsupported."
) from e
raise ValueError("YAML files with recursive references are unsupported.") from e
except ValidationError:
raise
except Exception as e:
Expand Down Expand Up @@ -238,9 +236,7 @@ def parse_file(
content_type = "application/yaml"

# Check whether we're specifically asked to parse YAML
is_yaml = is_yaml_requested(
content_type=content_type, proto=proto, path_suffix=path.suffix
)
is_yaml = is_yaml_requested(content_type=content_type, proto=proto, path_suffix=path.suffix)

# The first code path explicitly checks YAML compatibility.
# We offload the rest to Pydantic.
Expand Down

0 comments on commit 54ff4ba

Please sign in to comment.