Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Mypy's strict mode #217

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,5 @@ repos:
rev: v1.11.2
hooks:
- id: mypy
additional_dependencies:
- django-stubs==5.1.0
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,10 @@ enable_error_code = [
"redundant-expr",
"truthy-bool",
]
check_untyped_defs = true
disallow_any_generics = true
disallow_incomplete_defs = true
disallow_untyped_defs = true
mypy_path = "src/"
namespace_packages = false
no_implicit_optional = true
strict = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
Expand Down
7 changes: 5 additions & 2 deletions src/auto_prefetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ def _fetch_all(self) -> None:
if (
set_peers
and issubclass(self._iterable_class, models.query.ModelIterable)
and self._result_cache is not None
and len(self._result_cache) >= 2
):
peers = WeakValueDictionary((id(o), o) for o in self._result_cache)
Expand All @@ -111,6 +112,8 @@ def _fetch_all(self) -> None:


class Model(models.Model):
_peers: WeakValueDictionary[str, Model]

class Meta:
abstract = True
base_manager_name = "prefetch_manager"
Expand All @@ -129,8 +132,8 @@ def __getstate__(self) -> dict[str, Any]:
return res

@classmethod
def check(cls, **kwargs: Any) -> list[checks.Error]:
errors: list[checks.Error] = super().check(**kwargs)
def check(cls, **kwargs: Any) -> list[checks.CheckMessage]:
errors: list[checks.CheckMessage] = super().check(**kwargs)
errors.extend(cls._check_meta_inheritance())
return errors

Expand Down
2 changes: 1 addition & 1 deletion tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def test_multiples(django_assert_num_queries, Model, queries):

@pytest.mark.django_db
def test_garbage_collection():
def check_instances(num):
def check_instances(num: int) -> None:
gc.collect()
objs = [o for o in gc.get_objects() if isinstance(o, Prefetch)]
assert len(objs) == num
Expand Down