Skip to content

Commit

Permalink
build: #27-work 🛠 Switch to pyright + basic project cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ddanier committed Feb 16, 2024
1 parent 06a81a9 commit aa88121
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
- name: Lint with ruff & mypy
run: |
poetry run ruff check pydantic_changedetect tests
poetry run mypy pydantic_changedetect
poetry run pyright pydantic_changedetect
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: check-added-large-files
- id: check-merge-conflict
- id: check-docstring-first
- id: debug-statements
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.291
rev: v0.2.1
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/Lucas-C/pre-commit-hooks-safety
rev: v1.3.2
rev: v1.3.3
hooks:
- id: python-safety-dependencies-check
- repo: https://github.com/alessandrojcm/commitlint-pre-commit-hook
rev: v9.5.0
rev: v9.11.0
hooks:
- id: commitlint
stages: [commit-msg]
Expand Down
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ test-all: (poetry "run" "tox")

ruff *args: (poetry "run" "ruff" "check" "pydantic_changedetect" "tests" args)

mypy *args: (poetry "run" "mypy" "pydantic_changedetect" args)
pyright *args: (poetry "run" "pyright" "pydantic_changedetect" args)

lint: ruff mypy
lint: ruff pyright

publish: (poetry "publish" "--build")
8 changes: 5 additions & 3 deletions pydantic_changedetect/_compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, Optional, Type
from typing import Any, Dict, Type

import pydantic
from pydantic.fields import FieldInfo
Expand All @@ -8,7 +8,7 @@
PYDANTIC_V2 = PYDANTIC_VERSION.startswith("2.")

if PYDANTIC_V1: # pragma: no cover
class PydanticCompat:
class PydanticCompat: # type: ignore
obj: pydantic.BaseModel

def __init__(
Expand Down Expand Up @@ -38,5 +38,7 @@ def __init__(
def model_fields(self) -> Dict[str, FieldInfo]:
return self.obj.model_fields

def get_model_field_info_annotation(self, model_field: FieldInfo) -> Optional[Type[Any]]:
def get_model_field_info_annotation(self, model_field: FieldInfo) -> Type[Any]:
if model_field.annotation is None:
raise RuntimeError("model field has not typing annotation")
return model_field.annotation
6 changes: 3 additions & 3 deletions pydantic_changedetect/changedetect.py
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ def copy(
# The following methods are SLIGHTLY different fpr v1 and v2, so we need to keep
# them separate

def dict(
def dict( # type: ignore
self,
*,
include: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None,
Expand Down Expand Up @@ -569,7 +569,7 @@ def dict(
),
)

def json(
def json( # type: ignore
self,
include: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None,
exclude: Optional[Union['AbstractSetIntStr', 'MappingIntStrAny']] = None,
Expand Down Expand Up @@ -609,7 +609,7 @@ def construct(cls: Type["Model"], *args: Any, **kwargs: Any) -> "Model":
m.model_reset_changed()
return m

def _copy_and_set_values(
def _copy_and_set_values( # type: ignore
self: "Model",
values: 'DictStrAny',
fields_set: 'SetStr',
Expand Down
4 changes: 2 additions & 2 deletions pydantic_changedetect/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import warnings
from typing import Any, Dict, List, Mapping, Set, Tuple, Union, get_args, get_origin
from typing import Any, Dict, List, Mapping, Set, Tuple, Type, Union, get_args, get_origin

import pydantic_changedetect

Expand Down Expand Up @@ -38,7 +38,7 @@ def safe_issubclass(cls: Any, type_: Any) -> bool:
return False


def is_pydantic_change_detect_annotation(annotation: type) -> bool:
def is_pydantic_change_detect_annotation(annotation: Type[Any]) -> bool:
"""
Return True if the given annotation is a ChangeDetectionMixin annotation.
"""
Expand Down
10 changes: 6 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ pydantic = ">=1.9.0,<3.0.0"
[tool.poetry.group.dev.dependencies]
pytest = ">=7.1.2,<9.0.0"
pytest-cov = ">=3,<5"
mypy = ">=0.971,<2.0"
tox = ">=3.26,<5.0"
ruff = ">=0.0.284,<0.3.0"
pyright = ">=1.1.350,<1.2"

[tool.ruff]
select = ["F","E","W","C","I","N","UP","ANN","S","B","A","COM","C4","T20","PT","ARG","TD","RUF"]
line-length = 115
target-version = "py38"
ignore = ["A001","A002","A003","ANN101","ANN102","ANN401","C901","N8","B008","F405","F821"]
output-format = "grouped"

[tool.ruff.per-file-ignores]
[tool.ruff.lint]
select = ["F","E","W","C","I","N","UP","ANN","S","B","A","COM","C4","T20","PT","ARG","TD","RUF"]
ignore = ["A001","A002","A003","ANN101","ANN102","ANN401","C901","N8","B008","F405","F821"]

[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["F401"]
"conftest.py" = ["S101","ANN","F401"]
"test_*.py" = ["S101","ANN","F401"]
Expand Down

0 comments on commit aa88121

Please sign in to comment.