jazzband / jazzband/django-model-utils

Add type annotations

Open
#558 33 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.8k
Forks
375
PR merge metrics
No merged PRs in 30d

Description

Problem

When type-checking a model that uses InheritanceManager using mypy, the following error is displayed:

app/models.py:39: error: Could not resolve manager type for
"app.models.MyModel.objects"  [django-manager-missing]
        objects = InheritanceManager()
        ^

According to this Stack Overflow post, the origin of this problem is the django-stubs mypy plugin being unable to find InheritanceManager because django-model-utils does not provide type annotations.

According to the linked post, no actual annotations are required, just a marker that the package is annotated. But I think real annotations would be good to have anyway, both for users and developers of django-model-utils.

I am working on adding annotations to django-model-utils. I don't know if I'll have enough time to completely annotate it, but I'll share what I have in any case, probably tomorrow.

Environment

  • Django Model Utils version: 4.3.1
  • Django version: 3.2
  • Python version: 3.9
  • Other libraries used, if any: django-stubs 1.16.0

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no repository files or tests beyond the example app/models.py and InheritanceManager entry point. Start by reproducing the django-stubs mypy error with that model, then inspect django-model-utils' public utilities and existing test coverage. Done means the package is recognized as typed and the agreed annotation scope is covered without breaking supported Django and Python versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
django, python
Domain
backend, developer-experience
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.