Skip to content

Commit

Permalink
ci: clearing ruff check violations (#39)
Browse files Browse the repository at this point in the history
* refactor: replace for loop with builtin - SIM110

* ci: noqa imports

* ci: apply fixes for ruff - F811, PLR1714, RUF100

* ci: annotate mutable class attributes - RUF012

* docs: define arg descriptions in docstrings
  • Loading branch information
IndexSeek authored Oct 4, 2024
1 parent bca61b7 commit 5bd95a5
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 22 deletions.
4 changes: 3 additions & 1 deletion koerce/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import sys

from ._internal import *
from ._internal import * # noqa: F403


class _Variable(Deferred):
Expand Down Expand Up @@ -84,6 +84,8 @@ def koerce(
The value to match.
context
Arbitrary mapping of values to be used while matching.
allow_coercion
Whether to allow coercion of values to match the pattern.
Returns
-------
Expand Down
6 changes: 3 additions & 3 deletions koerce/_internal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from .annots import *
from .builders import *
from .patterns import *
from .annots import * # noqa: F403
from .builders import * # noqa: F403
from .patterns import * # noqa: F403

compiled = False
2 changes: 1 addition & 1 deletion koerce/annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ def __new__(
else:
is_initable = initable
for parent in bases:
try: # noqa: SIM105
try:
spec = parent.__spec__
except AttributeError:
continue
Expand Down
8 changes: 6 additions & 2 deletions koerce/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,9 +803,9 @@ def match(self, value, ctx: Context):
return True
if isinstance(value, str):
lowered = value.lower()
if lowered == "true" or lowered == "1":
if lowered in ["true", "1"]:
return True
elif lowered == "false" or lowered == "0":
elif lowered in ["false", "0"]:
return False
raise MatchError(self, value)

Expand Down Expand Up @@ -2569,6 +2569,10 @@ def pattern(
obj
The object to create a pattern from. Can be a pattern, a type, a callable,
a mapping, an iterable or a value.
allow_coercion
Whether to allow type coercion during matching.
self_qualname
The qualified name of the class that is being constructed.
Examples
--------
Expand Down
13 changes: 4 additions & 9 deletions koerce/tests/test_annots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Annotated,
Any,
Callable,
ClassVar,
Generic,
Mapping,
Optional,
Expand Down Expand Up @@ -996,10 +997,7 @@ def __eq__(self, other) -> bool:
return NotImplemented
if len(self) != len(other):
return False
for a, b in zip(self, other):
if a != b:
return False
return True
return all(a == b for a, b in zip(self, other))


# AnnotableMeta doesn't extend ABCMeta, so we need to register the class
Expand Down Expand Up @@ -1048,10 +1046,7 @@ def __eq__(self, other) -> bool:
return NotImplemented
if len(self) != len(other):
return False
for key in self:
if self[key] != other[key]:
return False
return True
return all(self[key] == other[key] for key in self)

def items(self):
for key in self:
Expand Down Expand Up @@ -2180,7 +2175,7 @@ class User(Annotable):
id: int
name: str = "Jane Doe"
age: int | None = None
children: list[str] = []
children: ClassVar[list[str]] = []

assert User.__spec__.initable is False
assert User.__spec__.immutable is False
Expand Down
1 change: 0 additions & 1 deletion koerce/tests/test_builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
Var,
builder,
deferrable,
resolve,
)

_ = Deferred(Var("_"))
Expand Down
8 changes: 4 additions & 4 deletions koerce/tests/test_y.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from dataclasses import dataclass
from inspect import Signature as InspectSignature
from typing import Generic
from typing import ClassVar, Generic

import pytest

Expand Down Expand Up @@ -161,21 +161,21 @@ class PUser(BaseModel):
id: int
name: str = "Jane Doe"
age: int | None = None
children: list[str] = []
children: ClassVar[list[str]] = []


class KUser(Annotable):
id: int
name: str = "Jane Doe"
age: int | None = None
children: list[str] = []
children: ClassVar[list[str]] = []


class MUser(msgspec.Struct):
id: int
name: str = "Jane Doe"
age: int | None = None
children: list[str] = []
children: ClassVar[list[str]] = []


data = {"id": 1, "name": "Jane Doe", "age": None, "children": []}
Expand Down
2 changes: 1 addition & 1 deletion koerce/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import sys
import typing
from collections.abc import Hashable, Mapping, Sequence, Set
from typing import Any, ClassVar, ForwardRef, Optional, TypeVar
from typing import Any, ForwardRef, Optional, TypeVar

from typing_extensions import Self

Expand Down

0 comments on commit 5bd95a5

Please sign in to comment.