Skip to content

Commit

Permalink
Use Mypy's strict mode
Browse files Browse the repository at this point in the history
  • Loading branch information
adamchainz committed May 18, 2023
1 parent ad954fc commit 570b313
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ repos:
rev: v1.3.0
hooks:
- id: mypy
additional_dependencies:
- django-stubs==1.14.0
7 changes: 1 addition & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,11 @@ addopts = """\
django_find_project = false

[tool.mypy]
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
show_error_codes = true
strict = true
warn_unreachable = true
warn_unused_ignores = true

[[tool.mypy.overrides]]
module = "tests.*"
Expand Down
8 changes: 5 additions & 3 deletions src/auto_prefetch/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ReverseOneToOneDescriptor(
def _is_cached(self, instance: models.Model) -> bool:
return self.related.is_cached(instance)

def _field_name(self) -> str:
def _field_name(self) -> str | None:
return self.related.get_accessor_name()


Expand Down Expand Up @@ -113,6 +113,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 @@ -131,8 +133,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 @@ -204,7 +204,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

0 comments on commit 570b313

Please sign in to comment.