Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ ci:

repos:
- repo: https://github.com/abravalheri/validate-pyproject
rev: v0.23
rev: v0.24.1
hooks:
- id: validate-pyproject

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.9.1
rev: v0.12.1
hooks:
- id: ruff
args: [--fix]
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.14.1
rev: v1.16.1
hooks:
- id: mypy
files: "^src/"
Expand Down
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test = [
"pydantic",
"annotated_types",
]
dev = ["black", "ipython", "mypy", "pdbpp", "rich", "ruff", "hatch"]
dev = ["ipython", "mypy", "pdbpp", "rich", "ruff", "hatch", "pre-commit-uv"]

[project.urls]
homepage = "https://github.com/pyapp-kit/fieldz"
Expand Down Expand Up @@ -88,7 +88,7 @@ select = [
"C4", # flake8-comprehensions
"A001", # flake8-builtins
"RUF", # ruff-specific rules
"TCH", # typecheck
"TC", # typecheck
"TID", # tidy imports
]
ignore = [
Expand All @@ -97,7 +97,7 @@ ignore = [
]

[tool.ruff.lint.per-file-ignores]
"tests/*.py" = ["D", "S"]
"tests/*.py" = ["D", "S", "RUF009"]
"setup.py" = ["D"]

# https://mypy.readthedocs.io/en/stable/config_file.html
Expand Down
6 changes: 3 additions & 3 deletions src/fieldz/adapters/_attrs.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def fields(class_or_instance: Any | type) -> tuple[Field, ...]:
)
fields: list[Field] = []
for f in attrs.fields(cls):
f = cast(attrs.Attribute, f)
f = cast("attrs.Attribute", f)
default = Field.MISSING if f.default is attrs.NOTHING else f.default
default_factory: (
Callable[[], Any] | Callable[[Any], Any] | Literal[_MISSING_TYPE.MISSING]
Expand All @@ -76,9 +76,9 @@ def fields(class_or_instance: Any | type) -> tuple[Field, ...]:
type=f.type,
default=default,
default_factory=default_factory,
repr=f.repr,
repr=f.repr, # type: ignore [arg-type]
init=f.init,
compare=f.eq,
compare=f.eq, # type: ignore [arg-type]
kw_only=f.kw_only,
hash=f.hash,
native_field=f,
Expand Down
4 changes: 3 additions & 1 deletion src/fieldz/adapters/_pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@
if hasattr(obj, "__pydantic_fields__"): # v2 dataclass
_fields = obj.__pydantic_fields__.items()
else:
if not isinstance(obj, type):
obj = type(obj)

Check warning on line 142 in src/fieldz/adapters/_pydantic.py

View check run for this annotation

Codecov / codecov/patch

src/fieldz/adapters/_pydantic.py#L141-L142

Added lines #L141 - L142 were not covered by tests
_fields = obj.model_fields.items()

annotations = getattr(obj, "__annotations__", {})
Expand Down Expand Up @@ -178,7 +180,7 @@
| type[pydantic.BaseModel]
| type[PydanticV1BaseModel],
) -> tuple[Field, ...]:
if hasattr(obj, "model_fields") or hasattr(obj, "__pydantic_fields__"):
if hasattr(type(obj), "model_fields") or hasattr(obj, "__pydantic_fields__"):
obj = cast("pydantic.BaseModel | type[pydantic.BaseModel]", obj)
return tuple(_fields_v2(obj))
if hasattr(obj, "__pydantic_model__"):
Expand Down