diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..17565ef --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,21 @@ +name: Ruff Check + +on: [push, pull_request] +permissions: + contents: read +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install ruff + - name: Analysing the code with pylint + run: | + ruff check diff --git a/koerce/__init__.py b/koerce/__init__.py index 59f0e93..fcc8be1 100644 --- a/koerce/__init__.py +++ b/koerce/__init__.py @@ -5,13 +5,13 @@ from ._internal import * # noqa: F403 -class _Variable(Deferred): +class _Variable(Deferred): #noqa: F405 def __init__(self, name: str): - builder = Var(name) + builder = Var(name) # noqa: F405 super().__init__(builder) def __pos__(self): - return Capture(self) + return Capture(self) # noqa: F405 def __neg__(self): return self @@ -50,8 +50,8 @@ def var(name): def namespace(module): - p = _Namespace(pattern, module) - d = _Namespace(deferred, module) + p = _Namespace(pattern, module) # noqa: F405 + d = _Namespace(deferred, module) # noqa: F405 return p, d @@ -59,7 +59,7 @@ def replace(matcher): """More convenient syntax for replacing a value with the output of a function.""" def decorator(replacer): - return Replace(matcher, replacer) + return Replace(matcher, replacer) # noqa: F405 return decorator @@ -72,8 +72,8 @@ def __init__(self): def koerce( - pat: Pattern, value: Any, context: Context = None, allow_coercion: bool = False -) -> Any: + pat: Pattern, value: Any, context: Context = None, allow_coercion: bool = False # noqa: F405 +) -> Any: # noqa: F405 """Match a value against a pattern. Parameters @@ -106,10 +106,10 @@ def koerce( ... ] """ - pat = pattern(pat, allow_coercion=allow_coercion) + pat = pattern(pat, allow_coercion=allow_coercion) # noqa: F405 try: return pat.apply(value, context) - except MatchError: + except MatchError: # noqa: F405 return NoMatch diff --git a/koerce/annots.py b/koerce/annots.py index 092a787..3c3a8ca 100644 --- a/koerce/annots.py +++ b/koerce/annots.py @@ -838,7 +838,7 @@ def __call__(cls, *args, **kwargs): class Singleton(Abstract): """Cache instances of the class based on instantiation arguments.""" - __instances__: Mapping[Any, Self] = WeakValueDictionary() + __instances__: Mapping[Any, typing.Self] = WeakValueDictionary() __slots__ = ("__weakref__",) diff --git a/koerce/tests/test_y.py b/koerce/tests/test_y.py index 9c0d564..20a768c 100644 --- a/koerce/tests/test_y.py +++ b/koerce/tests/test_y.py @@ -5,13 +5,6 @@ from typing import ClassVar, Generic import pytest - -pydantic = pytest.importorskip("pydantic") -msgspec = pytest.importorskip("msgspec") - -# from ibis.common.grounds import Annotable as IAnnotable -from pydantic import BaseModel, validate_call -from pydantic_core import SchemaValidator from typing_extensions import TypeVar from koerce import ( @@ -21,6 +14,11 @@ annotated, ) +msgspec = pytest.importorskip("msgspec") +pydantic = pytest.importorskip("pydantic") +from pydantic import BaseModel, validate_call # noqa: E402 +from pydantic_core import SchemaValidator # noqa: E402 + T = TypeVar("T") S = TypeVar("S") U = TypeVar("U")