Skip to content

Commit

Permalink
compat python 3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
getzze committed Feb 9, 2024
1 parent e510bf8 commit 661911c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
21 changes: 11 additions & 10 deletions src/psygnal/_dataclass_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,9 +218,9 @@ def iter_fields(
if not p_field.frozen or not exclude_frozen:
yield field_name, p_field.annotation
else:
for p_field in cls.__fields__.values():
if p_field.field_info.allow_mutation or not exclude_frozen:
yield p_field.name, p_field.outer_type_
for p_field in cls.__fields__.values(): # type: ignore [attr-defined]
if p_field.field_info.allow_mutation or not exclude_frozen: # type: ignore [attr-defined]
yield p_field.name, p_field.outer_type_ # type: ignore [attr-defined]

Check warning on line 223 in src/psygnal/_dataclass_utils.py

View check run for this annotation

Codecov / codecov/patch

src/psygnal/_dataclass_utils.py#L222-L223

Added lines #L222 - L223 were not covered by tests
return

attrs_fields = getattr(cls, "__attrs_attrs__", None)
Expand All @@ -240,14 +240,15 @@ def iter_fields(
class FieldOptions:
name: str
type_: type | None = None
_: KW_ONLY = KW_ONLY # set the value for compatibility with python < 3.10
# set KW_ONLY value for compatibility with python < 3.10
_: KW_ONLY = KW_ONLY # type: ignore [valid-type]
alias: str | None = None
skip: bool | None = None
eq: EqOperator | None = None
disable_setattr: bool | None = None


def is_kw_only(f: Field):
def is_kw_only(f: Field) -> bool:
if hasattr(f, "kw_only"):
return f.kw_only
# for python < 3.10
Expand Down Expand Up @@ -287,7 +288,7 @@ def get_msgspec_metadata(
single_meta: dict[str, Any] = getattr(meta, "extra", {}).get(
PSYGNAL_METADATA, {}
)
metadata |= single_meta
metadata.update(single_meta)

return type_, metadata

Expand Down Expand Up @@ -391,13 +392,13 @@ class Foo(BaseModel):
)
"""
for p_field in cls.__fields__.values():
if p_field.field_info.allow_mutation or not exclude_frozen:
meta_dict = getattr(p_field.field_info, "extra", {}).get("metadata", {})
for p_field in cls.__fields__.values(): # type: ignore [attr-defined]
if p_field.field_info.allow_mutation or not exclude_frozen: # type: ignore [attr-defined]
meta_dict = getattr(p_field.field_info, "extra", {}).get("metadata", {}) # type: ignore [attr-defined]
metadata = meta_dict.get(PSYGNAL_METADATA, {})

metadata = sanitize_field_options_dict(metadata)
options = FieldOptions(p_field.name, p_field.outer_type_, **metadata)
options = FieldOptions(p_field.name, p_field.outer_type_, **metadata) # type: ignore [attr-defined]
yield options
return

Expand Down
3 changes: 1 addition & 2 deletions tests/test_custom_fields.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# from __future__ import annotations
# from __future__ import annotations # breaks msgspec Annotated

import contextlib
from typing import ClassVar, Union
Expand All @@ -14,7 +14,6 @@
SignalGroupDescriptor,
)

# from typing import Annotated # type: ignore
Annotated = Union
with contextlib.suppress(ImportError):
from typing import Annotated # type: ignore
Expand Down

0 comments on commit 661911c

Please sign in to comment.