-
-
Notifications
You must be signed in to change notification settings - Fork 505
Closed as not planned
Labels
bugSomething isn't workingSomething isn't working
Description
Bug report
Mypy error in function
from contextlib import suppress
from typing import Type
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import Model
def get_next_pk(model: Type[Model]) -> int:
pk = 1
with suppress(ObjectDoesNotExist):
pk = model.objects.latest('pk').pk + 1
return pk
mypy.ini
[mypy]
python_version = 3.11
plugins = mypy_django_plugin.main, mypy_drf_plugin.main
exclude = .git, .idea, .mypy_cache, .ruff_cache, node_modules
cache_dir = ./.cache/mypy
check_untyped_defs = true
disallow_untyped_decorators = true
disallow_untyped_calls = true
ignore_errors = false
ignore_missing_imports = true
implicit_reexport = false
local_partial_types = true
no_implicit_optional = true
strict_optional = true
strict_equality = true
warn_unused_ignores = true
warn_redundant_casts = true
warn_unused_configs = true
warn_unreachable = true
warn_no_return = true
[mypy.plugins.django-stubs]
django_settings_module = 'settings'
What's wrong
After run mypy .
I receive next error:
apps/core/functions/get_next_pk.py:11: error: "type[Model]" has no attribute "objects" [attr-defined]
System information
- OS: Ubuntu 22.04
python
version: 3.11django
version: 4.2.5mypy
version: 1.5.1django-stubs
version: 4.2.4django-stubs-ext
version: 4.2.2
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working